关闭窗口(退出按钮/ command + w)不会退出主循环(Python 3.6-Tkinter)

时间:2018-06-25 11:57:00

标签: python-3.x tkinter

我想通过单击窗口退出按钮或Command / Control + W关闭窗口来停止程序。 我以为是自动的。 High Sierra + Python 3.6 + Tkinter 8.6

import tkinter as tk
root = tk.Tk()
texto = tk.StringVar(master=root) 
texto.set("Un nuevo texto")

tk.Label(root, text="¡Hola mundo!").pack(anchor="nw")
label = tk.Label(root, text="¡Otra etiqueta!")
label.pack(anchor="center")
tk.Label(root, text="¡Última etiqueta!").pack(anchor="se")
label.config(bg="green", fg="blue", font=("Verdana",24))
label.config(textvariable=texto)

imagen = tk.PhotoImage(master=root, file="lena.png") 

tk.Label(root, image=imagen, bd=0).pack(side="left")

root.mainloop()

1 个答案:

答案 0 :(得分:1)

从IDLE(Python 3.6 64位)运行代码。关闭按钮对我有用。