python - 必须为多个窗口重复按下 Tkinter 的“退出”按钮
问题描述
我正在开发一个显示 matplotlib 图形的 Tkinter GUI。我使用变量“window”来初始化 Tk 解释器;而不是“根”/“主”= Tk()。GUI 由 MyWindow 类格式化。
class MyWindow:
def __init__(self, win):
三个 GUI 'visual' 按钮显示 matplotlib 图形。mpl 图形的函数位于一个名为“charts”的模块中。在下面的示例中,“概览”是一个可视按钮。
self.btn5=Button(win, text='Overview')
self.b5=Button(win, text='Overview', width='6', height='2', command=self.overview)
self.b5.place(x=50, y=160)
def overview(self):
from charts import overview
overview()
“退出”按钮退出可视窗口和 GUI 本身。退出按钮代码:
self.btn6=Button(win, text='Quit')
self.b6=Button(win, text='Quit', width='6', height='2', command=window.quit)
self.b6.place(x=50, y=230)
def quit(self):
self.win.destroy()
除“退出”按钮外,所有功能都按预期工作。我必须单击“退出”的次数与 GUI 打开的窗口数一样多才能使其工作。
即我启动 GUI 并打开“概览”视觉;我需要单击“退出”两次以关闭“概览”和 GUI 本身。
我已经尝试将退出按钮“命令”和退出功能调整为带有前缀 self、win 和 window(并且没有前缀)的 destroy() / quit() 的所有组合。
解决方案
尝试使用Python
调用它的内置函数quit()
只会退出程序,杀死它的进程。
def quit(self):
quit()
推荐阅读
- python - 将 postgres 原始查询转换为 Django ORM 查询并分组
- python-3.x - 无法使用硒(python)在网页上单击打印(图像元素)
- javascript - 如何制作单页导航?没有滚动,只是一个带有自己身体的导航
- javascript - SyntaxError:位置 0 处的 JSON 中的意外令牌 u(Ropsten 测试网)
- python - Python URLencoding 特定结果
- django - 有什么方法可以请求从 Angular 应用程序到 django 的客户端区域基础数据检索?
- windows - 在 Vim 中使用 Yank 复制到 Windows 10 上的剪贴板
- javascript - 失败的 Axios 获取请求的控制台日志原始数据
- ios - 为什么没有要编译的架构 (ONLY_ACTIVE_ARCH=YES, active arch=arm64, VALID_ARCHS=)
- ios - 如何修复错误:“线程 1:EXC_BAD_ACCESS(代码=2,地址=0x7ffee0761ed8)”