【问题标题】:Prevent tkinter window from minimizing but able to maximise and close window防止 tkinter 窗口最小化但能够最大化和关闭窗口
【发布时间】:2021-12-31 20:16:51
【问题描述】:

我想阻止我的 tkinter 窗口最小化但能够最大化并关闭窗口。

类似的东西

我该怎么做?

【问题讨论】:

标签: python user-interface tkinter window minimize


【解决方案1】:

如果你的平台是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

【讨论】:

  • 非常感谢!有用!您介意简要解释一下代码吗?谢谢。编辑:就像 win32con.GWL_STYLE 做了什么
  • @CDN 更新答案并解释每个步骤。
  • @CDN 有关SetWindowLong()window styles 的详细信息。
猜你喜欢
  • 1970-01-01
  • 2020-06-26
  • 2013-10-09
  • 1970-01-01
  • 2013-04-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多