在Python 2.7.10程序上工作,對於密碼gui,但它給出應用程序未定義的錯誤。我不確定是否類應用程序(框架)或應用程序(應用程序)(根)有問題,因爲它要求我定義應用程序,但我不明白爲什麼他們會問我。Python-2.7.10密碼GUI不起作用
from Tkinter import *
class Application(Frame):
def _init_(self, master):
Frame._init_(self,master)
self.grid()
self.create_widgets()
def create_widgets(self):
self.instruction = Label(self, text = "Enter the password")
self.instruction.grid(row = 0, column = 0, columnspan = 2, sticky = W)
self.password = Entry(self)
self.password.grid(row = 1, column = 1, sticky = W)
self.submit_button = Button(self, text = "Submit", commmand = self.reveal)
self.submit_button.grid(row = 2, column = 0, sticky = W)
self.text = Text(self, width = 35, height = 5, wrap = WORD)
self.text.grid(row = 3, column = 0, columnspan = 2, sticky = W)
def reveal(self):
content = self.password.get()
if content == "password":
message = "You have the order"
else:
message = "Access denied."
self.text.delete(0.0, END)
self.text.insert(0.0, message)
root = Tk()
root.title("Password")
root.geometry("250x150")
app= Application(root)
root.mainloop()
您的縮進不正確。 'def'與'class Application(Frame)'具有相同的縮進級別。無論是否修復縮進問題,此代碼都不會給出您所說的錯誤。請給我們可運行的代碼,它實際上會產生你說的錯誤。 –
'__init__'中應該有'_' – furas
我建議在'app'和'='之間加一個空格。另外,你可以發佈你得到的_exact_錯誤嗎? –