如何在Windows中禁止窗口调整大小

4
我一直在使用Windows API调用,以便我可以让一些本地的Windows窗口样式与Tkinter配合使用。当我尝试阻止窗口可调整大小时,我遇到了问题。在窗口被映射之前使用root.resizable(False,False)会产生与root.overrideredirect(True)方法类似的效果; 在更改样式后调用它会导致各种疯狂的问题(窗口变得不稳定)。我想这里可能有一个特定于Windows的等效方法来实现root.resizable(False, False)。如何应对这个问题呢?请记住我拥有Tkinter窗口的句柄。
代码:
import Tkinter as tk
import string, win32ui, win32con

def decaption(event):
    root = event.widget

    # makes a handle to the window
    handle = string.atoi(root.wm_frame(), 0)

    # changes the style
    frame = win32ui.CreateWindowFromHandle(handle)
    frame.ModifyStyle(win32con.WS_CAPTION, 0, win32con.SWP_FRAMECHANGED)

    root.bind("<Map>", None)

root = tk.Tk()

# changes the style when the window is mapped
root.bind("<Map>", decaption)

root.mainloop()
2个回答

3

以下是一些想法:

  • You can try removing the WS_THICKFRAME style:

    frame.ModifyStyle(win32con.WS_THICKFRAME, 0)
    
  • Another alternative is to handle the WM_GETMINMAXINFO message that returns the minimum and maximum width and height for a window. In your case, you would return the current width and height. You can get this information with GetWindowRect.


2

我对Python的角度一无所知,但是防止窗口可调整大小的另一种方法(除了更改其样式)是处理WM_WINDOWPOSCHANGING并用您想要的大小覆盖新大小。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接