Search code examples
pythonwinapiwindows-7tkinterpywin32

Making a window not resizable in Windows


I've been working with Windows API calls so that I can get some native Windows window styles working with Tkinter. I've run into problems when I try to prevent the window from being resizable. Using root.resizable(False, False) before the window is mapped produces an effect not unlike that of the root.overrideredirect(True) method; calling it after the style has been changed causes all sorts of craziness (The window freaks out). I'm thinking that there's probably a windows specific equivalent to root.resizable(False, False). How would I get this working? Keep in mind I have a handle to the Tkinter window.

Code :

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()

Solution

  • I have no idea about the python angle, but another method to prevent a window from being resizable (in addition to changing its style) is to handle WM_WINDOWPOSCHANGING and override the new size with your desired size.