momo momo - 1 year ago 91
Python Question

What does overrideredirect do?

I have come to understand overrideredirect helps removing the default window decorations like the toolbar.What are its other uses? I am not very sure and couldn't find much documentation.

I am working on a mac. Using tkinter I want to obtain window which remains maxsize and cannot be resized,which i have achieved using geometry and resizable. What I need now is the guarantee that no random keystrokes by my user can close the window. Will overrideredirect help me in that? Is there any alternative?

Answer Source

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.resizable(False, False)

Drawback of this method: it always works on Microsoft Windows platform but it may not work on some Unix and MacOS platforms.


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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download