Removing or disabling a resizable Tkinter window maximise button under Windows [duplicate]

心不动则不痛 提交于 2019-12-25 04:14:02

问题


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


回答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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!