You can use overrideredirect()
and set its flag to True
. This will disable your window to be closed by regular means as mentioed in the link above. By regular means, it is meant the X button and the Alt + F4 keystrokes combination.
Since you used geometry()
and resizable()
, you will need to call update_idletasks()
to force the display to be updated before the application next idles.
Here is an example:
import Tkinter as Tk
root = Tk.Tk()
root.geometry('200x200+100+100')
root.resizable(False, False)
root.update_idletasks()
root.overrideredirect(True)
root.mainloop()
Drawback of this method: it always works on Microsoft Windows platform but it may not work on some Unix and MacOS platforms.
Edit:
You asked clarification about update_idletasks()
, I think it is better if I quote directly from its documentation as it is clearer (but if you do not understand this quotation, please let me know):
Some tasks in updating the display, such as resizing and redrawing
widgets, are called idle tasks because they are usually deferred until
the application has finished handling events and has gone back to the
main loop to wait for new events.
If you want to force the display to be updated before the application next idles, call the w.update_idletasks() method on any
widget.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…