防止 tkinter window 最小化但能够最大化和关闭 window
Prevent tkinter window from minimizing but able to maximise and close window
我想阻止我的 tkinter window 最小化但能够最大化和关闭 window。
像这样
我该怎么做?
如果你的平台是Windows(貌似是基于图片的),你可以通过pywin32
模块调用Windows函数来达到目的:
import tkinter as tk
import win32gui
import win32con
root = tk.Tk()
root.title('MinimizeTest')
root.geometry('300x200')
def disable_minbox():
# get window handle
win_id = root.winfo_id()
hwnd = win32gui.GetParent(win_id)
# get the current window style of root window
style = win32gui.GetWindowLong(hwnd, win32con.GWL_STYLE)
# mask out minimize button
style &= ~win32con.WS_MINIMIZEBOX
# update the window style of root window
win32gui.SetWindowLong(hwnd, win32con.GWL_STYLE, style)
# need to do it when root window is displayed
root.after(1, disable_minbox)
root.mainloop()
请注意,您需要使用 pip
安装 pywin32
:
pip install pywin32
我想阻止我的 tkinter window 最小化但能够最大化和关闭 window。
像这样
我该怎么做?
如果你的平台是Windows(貌似是基于图片的),你可以通过pywin32
模块调用Windows函数来达到目的:
import tkinter as tk
import win32gui
import win32con
root = tk.Tk()
root.title('MinimizeTest')
root.geometry('300x200')
def disable_minbox():
# get window handle
win_id = root.winfo_id()
hwnd = win32gui.GetParent(win_id)
# get the current window style of root window
style = win32gui.GetWindowLong(hwnd, win32con.GWL_STYLE)
# mask out minimize button
style &= ~win32con.WS_MINIMIZEBOX
# update the window style of root window
win32gui.SetWindowLong(hwnd, win32con.GWL_STYLE, style)
# need to do it when root window is displayed
root.after(1, disable_minbox)
root.mainloop()
请注意,您需要使用 pip
安装 pywin32
:
pip install pywin32