早些时候发布了一个关于无法正确定位某些内容的问题。那已经解决了,但现在我偶然发现了另一个问题。我尝试过将面向对象应用到python之前,我根本没有遇到任何问题。但是与GUI(tkinter)似乎有点不同。
这就是我做的事情
from tkinter import *
import tkinter.messagebox
class Validation:
def usrVali(self, name):
if name == " ":
tkinter.messagebox.showinfo( "Error","Usuario incorrecto")
else:
tkinter.messagebox.showinfo( "ok","dude")
vali = Validation()
form = Tk()
form.title("LogIn")
form.geometry("300x320+300+200")
usrIn = Entry(form, textvariable = None, width = 30)
usrIn.place(x = 60, y = 140)
user = usrIn.get()
passIn = Entry(form, textvariable = None, width = 30)
passIn.place(x = 60, y = 200)
usrLblVal = StringVar()
usrLblVal.set("User name")
usrLbl = Label(form, textvariable = usrLblVal )
usrLbl.place(x = 120, y = 115)
passLblVal = StringVar()
passLblVal.set("Password")
passLbl = Label(form, textvariable = passLblVal )
passLbl.place(x = 120, y = 175)
btn = Button(form, text = "Entrar", width = 10, command = vali.usrVali(user))
btn.place(x = 110, y = 250)
form.mainloop()
我的问题是在实际按下按钮之前调用方法。我想要按下按钮时调用方法而不是之前。感谢。