pythonwindows-7tkintertclwindow-style

Setting window styles with Tkinter/Tcl: no exit button


I know that Tkinter is just a thin layer over Tcl/Tk. Tkinter you can do a few things to change the windows styling. One example would be root.attributes('-toolwindow', True). This would change the window style, to that of a tool window. However, I'm looking to go a little bit lower level.

I suspect at some point Tcl/Tk refrences Windows window styles. I'm pretty sure it would have to do this in order to set the window style and by extension the Tkinter window styling. I'm trying to give a Tkinter window what I'm pretty sure is the WS_DLGFRAME style. However, I'm unsure how to approach this.

I'm wondering where in the Tcl/Tk part of Tkinter does it assign windows styles, and what I'd have to add to get this style.

The end goal is to get a Tkinter window border style that looks like the one below (note how it lacks an exit button):

enter image description here

This is in Windows 7, BTW.


Solution

  • If you are familiar with C, download Tk source code.

    I've looked quickly, and in this file: ./win/tkWinWm.c at line 3072 (tk859-src.zip), you have the function static int WmAttributesCmd(), dealing with -toolwindow as you've said, later updated by UpdateWrapper().

    So no easy way to change it, unless you change Tk source code.

    Alternatively you might be able to use FindWindow and look for Tk's window class TK_WIN_CHILD_CLASS_NAME defined to be TkChild, and then use SetWindowLongPtr( GWLP_STYLE, ...) to change the style (but this requires some ffi call to C or other means).

    I myself I'm not familiar with neither Tcl/Tk, so take it with a grain of salt. Why not try the Tcl/Tk community?