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