Unclosable window using tkinter

后端 未结 2 498
北荒
北荒 2021-01-23 00:24

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 win

2条回答
  •  余生分开走
    2021-01-23 01:21

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

    From this question:

    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()
    

    (edited code for 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.

提交回复
热议问题