2012-12-28 2 views
0

필자가 작성한 응용 프로그램을 테스트하고 있었지만 빈 창과 위젯이 없습니다.Tkinter 위젯이 나타나지 않음

from Tkinter import* 
class App(Frame): 

def _init_(self, master): 

    frame = Frame(master) 
    frane.pack() 

    self.instruction = Label(frame, text = 'Password:') 
    self.instruction.pack() 

    self.button = Button(frame, text = 'Enter', command = self.reveal) 
    self.button.pack() 


root = Tk() 
root.title('Password') 
root.geometry('350x250') 
App(root) 
root.mainloop() 

답변

3

몇 가지 오타가 있습니다. 첫 번째는 생성자 메서드의 이름입니다 :

def _init_(self, master): 

읽어야합니다

def __init__(self, master): 

주에게 이중 밑줄 - the docs for Python objects를 참조하십시오.

self.button = Button(frame, text="Enter", command=self.reveal) 

실무 예제는 읽습니다 : 당신은 또한 당신의 앱 클래스에 '공개'라는 방법에 대한 선언을 놓치고

frane.pack() 

:

두 번째는 생성자 내부

from Tkinter import * 

class App(Frame): 

    def __init__(self, master): 
     Frame.__init__(self, master) 
     self.pack() 

     frame = Frame() 
     frame.pack() 

     self.instruction = Label(frame, text="Password:") 
     self.instruction.pack() 

     self.button = Button(frame, text="Enter", command=self.reveal) 
     self.button.pack() 


    def reveal(self): 
     # Do something. 
     pass 


root = Tk() 
root.title("Password") 
root.geometry("350x250") 
App(root) 
root.mainloop() 

다음을 참조하십시오 : The Tkinter documentation.

+0

감사합니다. – zlittrell

관련 문제