我想防止我的 tkinter 視窗最小化但能夠最大化和關閉視窗。
像這樣的東西

我該怎么做呢?
uj5u.com熱心網友回復:
如果你的平臺是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()
請注意,您需要pywin32使用pip以下命令進行安裝:
pip install pywin32
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/365035.html
