我有一个创建对话框窗口的应用程序(
tk.Toplevel
)。我需要防止用户右键单击该窗口的标题栏并调出窗口管理选项的上下文菜单。除此之外,我想找到一种方法来防止最小化和最大化相关窗口。
我使用下面示例中显示的选项来防止手动调整窗口大小/最小化/最大化窗口。但是,标题栏上下文菜单仍然允许最小化和最大化窗口,我也想消除它。
import tkinter as tk
class App(tk.Tk):
def __init__(self):
super().__init__()
self.dlg = tk.Toplevel(self) # create child dialog window
self.dlg.focus() # focus dialog window upon creation
# something to look at...
self.content = tk.Label(self.dlg, text='Right-click my title bar!')
self.content.pack(expand=True, fill='both')
# set options
self.dlg.resizeable(False, False) # prevent drag resizing
self.dlg.transient(self) # show only close [x] button
# tried this, but it didn't work as desired - protocol is never triggered
self.dlg.protocol('WM_CONTEXTMENU', self.nocontext)
# tried this, but it only applies to right-click events *in* the
# window, not the titlebar
self.bind('<Button-3>', 'break')
def nocontext(self) -> None:
"""Attempt to dispose of window contextmenu events...fail"""
return None
如果有帮助,这个应用程序将在 Windows 下运行,解决方案不需要跨平台。非常感谢任何帮助!