Tkinter 正在尝试获取GUI,但什么也没有出现,没有GUI,命令窗口上也没有错误

Tkinter 正在尝试获取GUI,但什么也没有出现,没有GUI,命令窗口上也没有错误,tkinter,python-3.6,Tkinter,Python 3.6,输出中未显示任何内容,也未显示任何错误或窗口。行: import tkinter as tk window = tk.Tk() window.title("WORD GAME") def game(): print("Hi window !") heading_label1 = tk.Label(window, text="WANNA PLAY THE GAME ?? ....") heading_label1.pack() button1 = tk.Button(window, te

输出中未显示任何内容,也未显示任何错误或窗口。

行:

import tkinter as tk
window = tk.Tk()
window.title("WORD GAME")
def game():
    print("Hi window !")

heading_label1 = tk.Label(window, text="WANNA PLAY THE GAME ?? ....")
heading_label1.pack()
button1 = tk.Button(window, text="YES", command=lambda: game())
button1.pack()
button2 = tk.Button(window, text="NO", command=exit())
button2.pack()

window.mainloop()

实际上,在用括号结束
exit()
时运行退出命令

要将命令分配给按钮,只需提供名称:

button2 = tk.Button(window, text="NO", command=exit())

commnad=game
command=exit
不带
()
。但要关闭窗口,最好是
command=window.destroy
button2 = tk.Button(window, text="NO", command=exit)