0

Me estoy iniciando en el lenguaje de Python y en la plataforma, quisiera que me ayudaran un poco, ya cambie el tipo de variable (local, global) y me sigue saliendo el mismo error.

No he encontrado el problema. También me sale el error acompañado de esto :

Traceback (most recent call last):
  File "C:\Python\lib\tkinter\__init__.py", line 1883, in __call__
    return self.func(*args)
  File "C:/Users/danie/Desktop/PythonTriton/Clases/LoginWindow.py", line 5, in clicbotonIniciar
    print(var.get())
  TypeError: get() missing 1 required positional argument: 'self'
from tkinter import *

class LoginWindow():
    def clicbotonIniciar(self):

        print(var.get())
    def __init__(self):
        alto = "500"
        ancho = "500"
        window=Tk()
        window.title("Iniciar Sesión")

        pan_altura=window.winfo_screenheight()
        pan_ancho = window.winfo_screenwidth()
        res=round((pan_ancho/2)-(int(ancho)/2))
        res1=round((pan_altura/2)-(int(alto)/2))
        posicion="+"+str(res)+"+"+str(res1)
        anchoAlto=str(ancho)+"x"+str(alto)
        window.geometry(anchoAlto+posicion)
        window.resizable(False,False)
        window.iconbitmap("C:/Users/danie/Desktop/PythonTriton/Imagenes/Logo.ico")
        #window.overrideredirect(True)

        fuente="Arial Bold"
        fuenteBold="Arial Black"
        colorwindowFrame = "#%02x%02x%02x" % (51,51,51)
        color_rojo = "#%02x%02x%02x" % (255, 51, 51)

        windowFrame = Frame(window, width="500", height="500", bg=colorwindowFrame)
        windowFrame.pack()

        Imagen = PhotoImage(file="C:/Users/danie/Desktop/PythonTriton/Imagenes/LoginPruebaN.png")
        Label(windowFrame, text="Iniciar Sesión",fg="white",bg=colorwindowFrame, font=(fuente,18) ).place(x=190,y=0)
        Label(windowFrame, image=Imagen,bg=colorwindowFrame).place(x=200,y=25)
        Label(windowFrame,text="USUARIO", font=(fuenteBold,18),fg="white",bg=colorwindowFrame).place(x=190,y=150)
        Label(windowFrame, text="CONTRASEÑA", font=(fuenteBold, 18), fg="white", bg=colorwindowFrame).place(x=160, y=230)
        Label(windowFrame, text="Llave de\nacceso", font=(fuenteBold, 10), fg="white", bg=colorwindowFrame).place(x=137,y=310)


        textUser=Entry(windowFrame,font=("Arial",20), width="15")
        textUser.place(x=140,y=190)
        textPass=Entry(windowFrame, font=("Arial", 20), width="15", show="*")
        textPass.place(x=140, y=270)
        textRec=Entry(windowFrame,font=(fuente,10), show="*",width="11")
        textRec.place(x=230,y=320)

        botonIniciar=Button(windowFrame, text="Iniciar", font=(fuenteBold,14), bd="4", bg="#FF5811", fg="white", justify="center", width="12",activebackground="#FF7E00", command= self.clicbotonIniciar)
        botonIniciar.config(cursor="hand2", relief="flat", activeforeground="gray")
        botonIniciar.place(x=80,y=430)
        botonRegistrar = Button(windowFrame, text="Registrarse", font=(fuenteBold, 14), bd="4", bg="#FF5811", fg="white", activebackground="#FF7E00",width="12")
        botonRegistrar.config(cursor="hand2", relief="flat", activeforeground="gray")
        botonRegistrar.place(x=270, y=430)
        botonRecordar=Checkbutton(text="Recordar",bg=colorwindowFrame,font=(fuenteBold,12), activebackground=colorwindowFrame, fg="#808080",activeforeground="#FF5811")
        botonRecordar.config(onvalue=1,offvalue=0, variable=var)
        botonRecordar.place(x=137,y=350)
        botonCancelar=Button(windowFrame, text="X",bg=color_rojo, fg="white", font=(fuenteBold,11), width="2", activebackground="#FF4949", command = window.destroy)
        botonCancelar.config(cursor="hand2", relief="flat", activeforeground="white")
        botonCancelar.place(x=460,y=10)
        botonFAQ = Button(windowFrame, text="?", bg="#FF5811", fg="white", font=(fuenteBold, 11), width="2",activebackground="#FF7E00")
        botonFAQ.config(cursor="hand2", relief="flat", activeforeground="gray")
        botonFAQ.place(x=10, y=10)

        window.mainloop()
var = IntVar
ventanaLogin=LoginWindow()

2 respuestas 2

1

Ya encontré el error, esté se era que tenia la función IntVar() declarada antes de la función de la librería Tk(). La solucion es declarar la tanto la instancia de Tk()(de manera global) afuera y consecutivamente la instancia o variable de IntVar()

0

Antes que nada es importante diferenciar entre una clase y un objeto.

IntVar es la clase, un objeto de este sería var = IntVar().

Así como tú la estás declarando var = IntVar lo que le estás diciendo es que var es igual a la clase IntVar, no que es un objeto de la misma, para denotar un objeto es importante poner los paréntesis para que invoque al constructor y entonces se cree un objeto de este var = IntVar()

El error ocurre por lo mismo, todos los métodos que tienen como parámetro (self) solo pueden ser invocados por un objeto de dicha clase y no por la clase como tal.

Haciendo el cambio debería funcionar.

El código debería quedar como .

var = IntVar()
ventanaLogin=LoginWindow()

En esa parte, cambiando eso ese error ya no debería salir

3
  • Aún no entiendo bien. ¿Cómo sería el código con los respectivos cambios?
    – kass FX
    el 30 abr. 2020 a las 21:36
  • He editado la respuesta, agregando en donde tendrías que cambiar
    – Sr1871
    el 30 abr. 2020 a las 21:38
  • Ya lo había intentado de esa manera. Ahora que lo intento me sale el siguiente error: Traceback (most recent call last): File "C:/Users/danie/Desktop/PythonTriton/Clases/LoginWindow.py", line 64, in <module> var = IntVar() File "C:\Python\lib\tkinter_init_.py", line 529, in _init_ Variable.__init__(self, master, value, name) File "C:\Python\lib\tkinter_init_.py", line 335, in _init_ self._root = master._root() AttributeError: 'NoneType' object has no attribute '_root'
    – kass FX
    el 30 abr. 2020 a las 21:41

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.