0
I have the Login class and created an instance of it in the Main class, with the instance I am calling the start method, but in the start method when clicking the 'Log in' button the 'show_entry_fields' method is not executed correctly. When running and clicking the Main class I immediately get on the console: 'wrong login' . That is, I don’t know why, but it is running directly 'Else', without me having to click the button.(if is not running). Can anyone help or explain what I did wrong? Follow the code of both classes
from tkinter import *
class Login:
@staticmethod
def show_entry_fields(nome, senha):
if nome == 'admin' and senha == 'admin':
master.destroy()
else:
print('login errado')
@staticmethod
def iniciar():
master = Tk()
Label(master, text='Usuário').grid(row=0)
Label(master, text='Senha').grid(row=1)
e1 = Entry(master)
e2 = Entry(master)
e1.grid(row=0, column=1)
e2.grid(row=1, column=1)
Button(master, text='Sair', command=master.quit).grid(row=3, column=0, sticky=W, pady=4)
Button(master, text='Logar', command=Login.show_entry_fields(e1.get(), e2.get())).grid(row=3, column=1, sticky=W, pady=4)
mainloop()
main class:
from FechaLogin import Login
g = Login()
g.iniciar()
After pasting the auqi code, always use the button
{}
to shoot the code correctly– jsbueno