Removing or disabling a resizable Tkinter window maximise button under Windows

Malcolm picture Malcolm · Dec 2, 2010 · Viewed 8.2k times · Source

Looking for advice on how to remove or disable a resizable window's maximize button under Windows. I'm using Python 2.7 for Windows.

Background: I have a resizable window with min and max sizes set via the window's minsize() and maxsize() methods. When a user clicks the maximize button, the window moves to the upper left of the display. This is very confusing to my users so I would like to prevent that behavior.

My research shows several ways to disable a maximize button - but none of these techniques seem to apply to resizable windows?

  1. Prevent a window from resizing via the resizable( False, False ) method.

  2. Remove all the window's controls (and border) via the overrideredirect( True ) method.

  3. Use the mysterious transient(1) method (this raises an exception under Windows).

  4. Bind the window's event and try to block the maximize (update: Tkinter has already maximized the window by the time our handler detects the maximize event. Returning "break" or using geometry(size|position) to size and re-position a window are both ignored)

  5. I've posted a question on the Python Win32 API mailing list to see if we can use a Windows API call to disable a window's maximize button via the hWnd handle that I believe(?) Tkinter exposes.

Is there a way I can trap the maximize event (BEFORE Tkinter performs it)?

Malcolm

Answer

rayscan picture rayscan · Mar 25, 2011

One possibility is to set the window as a tool window but this also comes with side effects; the window will no longer appear in the taskbar and will have a thin title bar. It will still be able to be resized at the edges.

root.attributes("-toolwindow", 1)

More about the root attributes can be found in this guidebook.