2017-12-24 11 views
1

Tkinter에서 간단한 GUI를 만들고 응용 프로그램으로 변환하려고했습니다. 프로그램에 수동으로 만들어진 종료 버튼이 있습니다.이 버튼은 파이썬 프로그램 일 때 작동하지만 응용 프로그램을 만들 때는 작동하지 않습니다. 내 코드는 다음과 같습니다응용 프로그램으로 변환 한 후 Quit() 버튼이 작동하지 않습니다.

def exit(): 
    quit() 
def main(): 

    root = tk.Tk() 

    top = Frame(root) 
    bottom = Frame(root) 

    top.config(bg="lightgray") 
    top.pack(side=TOP) 

    bottom.config(bg="gray") 
    bottom.pack(side=BOTTOM, fill=BOTH, expand=True) 
    root.title("Quote of the Day") 
    root.overrideredirect(True) 

    root.lift() 
    root.wm_attributes("-transparentcolor", "white") 
    root.columnconfigure(0, weight=1) 
    root.rowconfigure(1, weight=1) 
    root.attributes('-alpha', 0.8) 
    root.iconbitmap("icon.png") 

    b1 = Button(root,text = " X ", command = exit, bg = None) 
    b1.config(width = 1, height = 1, borderwidth = 0) 

    b1.pack(in_=top, side=RIGHT) 
    root.mainloop() 

if __name__==('__main__'): 
    main() 
+0

'명령 = root.destroy'이 더 잘 작동 될 수 있습니다

그래서, 당신은 버튼 선언 줄을 수정해야합니다. 나는'quit()'이 주로 대화 형으로 사용되는 것을 의도한다고 믿는다. – jasonharper

+0

그래. 고맙습니다! – v0rtex

+0

[this guide] (https://stackoverflow.com/help/mcve)를 사용하여 예제를 제공해주십시오. 코드가 _incomplete_입니다. – Nae

답변

1

대신 종료를 호출하는 버튼의 명령을 설정하는 단지 root.destroy를 사용합니다.

b1 = Button(root,text = " X ", command = root.destroy, bg = None)