问题
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?
Prevent a window from resizing via the resizable( False, False ) method.
Remove all the window's controls (and border) via the overrideredirect( True ) method.
Use the mysterious transient(1) method (this raises an exception under Windows).
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)
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
回答1:
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.
来源:https://stackoverflow.com/questions/4333341/removing-or-disabling-a-resizable-tkinter-window-maximise-button-under-windows