2017-04-11 1 views
0

나는 파이썬과 코딩에 새로운 편이다. 게임용 응용 프로그램을 만들려고하고 있는데, 만든 프레임을 파괴 할 수 없습니다.파이썬 Tkinter 프레임 파괴

from tkinter import * 


class application: 

    def __init__(self,parent): 
     self.startContainer = Frame(parent) 
     self.startContainer.pack() 

     self.lbl = Label(startContainer,text="Please choose from the following: \nFaith Points (F) \nBanqueting Goods (B) \nEnter Honour (E) ") 
     self.lbl.pack() 

     self.btn1 = Button(startContainer,text="Votes",command=self.votes(startContainer)).pack() 
     self.btn2 = Button(startContainer,text="Gold Tithe",command=self.gold(startContainer)).pack() 

    def votes(parent,self): 
     parent.destroy() 

    def gold(parent,self): 
     pass 


window = Tk() 
app = application(window) 
window.title("Tools") 
window.geometry("425x375") 
window.wm_iconbitmap("logo.ico") 
window.resizable(width=False, height=False) 
window.mainloop() 
+1

첫 번째 인수는'self'되어야하지 (자기, ...) 등의 클래스 내에 함수 매개 변수를 구성하려고. 이것은 vote'와'gold' 메소드에 적용됩니다. 자세한 내용은이 [link] (http://stackoverflow.com/questions/2709821/what-is-the-purpose-of-self)를 참조하십시오. 'self '의 명칭은 단지 관습 일뿐 예약어는 아닙니다. – arrethra

답변

0

주 창 내부의 위젯에서 파괴를 호출합니다. "부모"의 파괴를 호출하십시오. 부모를 self.parent로 변환 : self.votes()를 호출 할 때 실제로 함수를 호출하면 함수가 열려지기 전에 함수가 파기됩니다.

은 또한 (... 자기) 방법을 정의 할 때

from tkinter import * 


class application: 

    def __init__(self,parent): 
     self.parent = parent 
     startContainer = Frame(parent) 
     startContainer.pack() 

     self.lbl = Label(startContainer,text="Please choose from the following: \nFaith Points (F) \nBanqueting Goods (B) \nEnter Honour (E) ") 
     self.lbl.pack() 

     self.btn1 = Button(startContainer,text="Votes", command=self.votes).pack() 
     self.btn2 = Button(startContainer,text="Gold Tithe",command=self.gold(startContainer)).pack() 

    def votes(self): 
     print("test") 
     self.parent.destroy() 

    def gold(self, parent): 
     pass 


window = Tk() 
app = application(window) 
window.mainloop()