What does overrideredirect do?

momo

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?

Billal Begueradj

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related