2011-05-06 7 views
3
from TKinter import * 

class Ui(Frame): 
    def __init__(self) 
    Frame.__init__(self, None) 

    self.grid() 
    bquit=Button(self, text="Quit", command=self.quit_pressed) 
    bquit.grid(row=0, column=0) 

    def quit_pressed(self): 
    self.destroy() 

app=Ui() 
app.mainloop() 

"Quit"버튼을 누를 때 왜 Tkinter 프로그램이 제대로 종료되지 않습니까?Python Tkinter 응용 프로그램이 제대로 종료되지 않습니다.

+0

IDLE을 사용하고 있습니까? –

+0

IDLE을 사용하지 않습니다. – jldupont

답변

4

는 self.destroy() 그냥, 프레임을 파괴하지 않는으로이 최상위 컨테이너가 제대로 종료하려면 self.master.destroy()를 수행해야합니다.

3

quit_pressed에서 프로그램을 끝내기 위해 잘못된 방법을 사용하고 있기 때문에 이것이 작동하지 않는 이유가 있습니다. 지금하고있는 일은 루트 프레임이 아닌 자체 프레임을 죽이는 것입니다. 자아 프레임은 루트 프레임에 격자 된 새로운 프레임이므로 자 체 프레임을 죽일 때 루트 프레임을 죽이지는 않습니다. 이것은 타이핑 스타일 때문에 혼란 스러울 수 있습니다. 예를 들어 보겠습니다.

현재, 당신은 당신이 할 수있는 기능을 변경하여이 문제를 해결 할 수 있습니다

def quit_pressed(self): 
    self.destroy() #This destroys the current self frame, not the root frame which is a different frame entirely 

,

def quit_pressed(self): 
    quit() #This will kill the application itself, not the self frame. 
관련 문제