相关疑难解决方法(0)

覆盖Tkinter"X"按钮控件(关闭窗口的按钮)

当用户按下我创建的关闭时 Button,某些任务在退出之前执行.但是,如果用户单击[X]窗口右上角的按钮关闭窗口,则无法执行这些任务.

如何覆盖用户单击[X]按钮时发生的情况?

python tkinter button

26
推荐指数
2
解决办法
4万
查看次数

Python Tkinter.仅显示一个窗口副本

我有一个问题.我有在Tkinter上写过的程序.

import Tkinter as tk
import ttk


def about_window():
    print(root.child_window)

    if not root.child_window:
        top2 = tk.Toplevel(root)
        top2.title("About")
        top2.resizable(0,0)

        explanation = "This program is my test program"

        ttk.Label(top2,justify=tk.LEFT,text=explanation).pack(padx=5,pady=2)
        ttk.Button(top2,text='OK',width=10,command=top2.destroy).pack(pady=8)


root = tk.Tk()
root.resizable(0,0)

root.child_window = None
#print(root.child_window)

root.style = ttk.Style()
# ('clam', 'alt', 'default', 'classic')
root.style.theme_use("clam")

menu = tk.Menu(root)
root.config(menu=menu)

fm = tk.Menu(menu, tearoff=0)
menu.add_cascade(label="Settings",menu=fm)
fm.add_command(label="Preferances")

hm = tk.Menu(menu, tearoff=0)
menu.add_cascade(label="Help",menu=hm)
hm.add_command(label="About", command=about_window)
hm.add_command(label="Exit",command=root.quit)
#

tk.mainloop()
Run Code Online (Sandbox Code Playgroud)

所以我可以点击"关于"标签,然后会看到窗口:

在此输入图像描述

但是在Tkinter中是否可以禁用同一窗口的任何下一次启动?

在此输入图像描述

我试过这个/sf/answers/1742076451/但没有成功.

python tkinter

3
推荐指数
2
解决办法
2563
查看次数

标签 统计

python ×2

tkinter ×2

button ×1