使用 tkinter 的不可关闭窗口 [英] Unclosable window using tkinter

查看:136
本文介绍了使用 tkinter 的不可关闭窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我正在制作一个程序,当我输入错误的密码时,它会使用我的网络摄像头拍照.该程序将打开,我希望它不可关闭.我需要知道如何使用 tkinter 使窗口不可关闭.

Hey I am making a program that take a picture using my webcam when I type the wrong password. The program will be open and I want it unclosable. I need to know how to make a window unclosable using tkinter.

推荐答案

您可以尝试@abarnert 建议的所有内容,但我认为最简单的方法是忽略关闭事件.

You can try all of the many things @abarnert suggested, but I think the easiest way would be to just ignore the close event.

来自这个问题:

这里有一个具体的例子:

Here you have a concrete example:

import Tkinter as tk
import tkMessageBox as messagebox
root = tk.Tk()

def on_closing():
    if messagebox.askokcancel("Quit", "Do you want to quit?"):
        root.destroy()

root.protocol("WM_DELETE_WINDOW", on_closing)
root.mainloop()

(为 Windows 编辑代码)

(edited code for Windows)

因此将 on_closure() 更改为
def on_closed():通行证
这使它无法关闭.我尝试了 Alt+F4,关闭按钮,从 Windows 任务栏关闭它,但无济于事.我能够杀死它的唯一方法是使用任务管理器.

So change on_closing() to
def on_closing(): pass
and that makes it unclosable. I tried Alt+F4, the close button, closing it from the Windows Taskbar, all to no avail. The only way I was able to kill it was to use Task Manager.

这篇关于使用 tkinter 的不可关闭窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆