在Windows下删除或禁用可调整大小的Tkinter窗口最大化按钮 [英] Removing or disabling a resizable Tkinter window maximise button under Windows

查看:145
本文介绍了在Windows下删除或禁用可调整大小的Tkinter窗口最大化按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

寻找有关如何在Windows下删除或禁用 resizable 窗口的最大化按钮的建议.我正在Windows上使用Python 2.7.

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.

背景:我有一个可调整大小的窗口,该窗口具有通过窗口的minsize()和maxsize()方法设置的最小和最大大小.当用户单击最大化按钮时,窗口将移至显示的左上方.这对我的用户来说非常混乱,因此我想防止这种行为.

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. 防止通过resizable(False,False)方法调整窗口大小.

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

通过overrideredirect(True)方法删除所有窗口的控件(和边框).

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

使用神秘的transient(1)方法(这在Windows下会引发异常).

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

绑定窗口的事件并尝试阻止最大化(更新:Tkinter在我们的处理程序检测到最大化事件时已将窗口最大化.返回"break"或使用geometry(size | position)调整大小和重新放置窗口都会被忽略)

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)

我已经在Python Win32 API邮件列表中发布了一个问题,以查看我们是否可以使用Windows API调用通过我相信(?)Tkinter公开的hWnd句柄来禁用窗口的最大化按钮.

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.

有没有办法捕获最大事件(在Tkinter执行之前)?

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

马尔科姆

推荐答案

一种可能是将窗口设置为工具窗口,但这也会带来副作用.该窗口将不再出现在任务栏中,并且将带有一个细标题栏.仍然可以在边缘调整大小.

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.

这篇关于在Windows下删除或禁用可调整大小的Tkinter窗口最大化按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆