class StartUp():
def __init__(self):
pass
def verify(self):
username = ("s")
password = ("s")
usernameEntry = usernameVar.get()
passwordEntry = passVar.get()
start = StartUp()
if usernameEntry == username and passwordEntry == password:
start.login()
else:
#messagebox.showerror("Error","Wrong Credentials")
def login(self):
#Create a window
global usernameVar, passVar
verify = StartUp()
window = Tk()
window.title("Login")
userPassLabel = Label(window, font="Helvetica 18 bold", text="Royal Mail")
userPassLabel.grid(row=0, column=0, sticky=W)
usernameVar = StringVar()
usernameLabel = Label(window, font="Arial", text="Username:")
usernameLabel.grid(row=1, column=0, sticky=W)
usernameEntry= Entry(window, width=30, bg="light blue",textvariable = usernameVar, )
usernameEntry.grid(row=1, column=1, sticky=W)
passVar = StringVar()
passLabel = Label(window, font="Arial", text="Password:")
passLabel.grid(row=2, column=0, sticky=W)
passEntry= Entry(window, width=30, bg="light blue",textvariable = passVar, show ="●")
passEntry.grid(row=2, column=1, sticky=W)
b1= Button(window, text="Enter", command=verify.verify())
b1.grid(row=3, column=0, sticky=W)
window.mainloop()
start = StartUp()
start.login()
该代码似乎不起作用。消息框只会弹出。然后输入按钮不起作用。不知道出了什么问题。我对 OOP 很陌生,所以不确定是否与此有关。
另一个问题是我如何能够将一个变量从一个窗口/类中的输入框传送到另一个窗口/类?全局是一个可行的选项,还是有更好的方法可以从条目框中使用 .get() 。
谢谢您的帮助