tkinter的新功能,但截至目前,我不知道为什么我的代码不断返回失败,而不是通过。为什么我的代码不工作?
import tkinter as tk
class GUI(tk.Tk):
def __init__(self):
tk.Tk.__init__(self)
self.entry = tk.Entry(self)
self.user_Label = tk.Label(self, text="Username")
self.pass_entry = tk.Entry(self)
self.pass_Label = tk.Label(self, text="Password")
self.login = tk.Button(self, text="Login", foreground="black", command=self.on_button)
#Packing
self.user_Label.pack()
self.entry.pack()
self.pass_Label.pack()
self.pass_entry.pack()
self.login.pack()
def on_button(self):
if self.entry and self.pass_entry == "hello":
print("passed")
else:
print("Failed")
app = GUI()
app.mainloop()
试试'如果self.pass_entry.get()==“你好”:...'为'self.pass_entry'永远等于' 'hello'(前者是一个tkinter小部件 - 后者是一个字符串)。 – mgilson 2015-02-12 06:40:40