【问题标题】:Closing window (exit button/command+w) does not quit mainloop (Python 3.6 - Tkinter)关闭窗口(退出按钮/命令+w)不会退出主循环(Python 3.6 - Tkinter)
【发布时间】:2018-12-03 23:57:33
【问题描述】:

当我使用单击窗口退出按钮或命令/控制+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()

【问题讨论】:

  • 我无法重现该问题。
  • 看你也问this question that no one could reproduce,问题不在你的代码。我猜你使用的 IDE 不能很好地与 tkinter 一起使用。您从哪里运行代码?
  • 我正在使用 Anaconda-Spyder 最新版本
  • @Javier:请edit您的问题包含该信息。除非您另有说明,否则我们假设您使用标准版本的 python 运行代码。

标签: python-3.x tkinter


【解决方案1】:

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

【讨论】:

  • 我正在使用 Anaconda-Spyder 最新版本。
  • 我会卸载并重新安装 spyder。如果那不能解决您的问题,那么我认为 Anaconda-Spyder 不能很好地与 tkinter 配合使用。 anaconda.org/anaconda/spyder
猜你喜欢
  • 2014-04-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-10
  • 1970-01-01
  • 2018-11-26
相关资源
最近更新 更多