3

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.

nbro
  • 15,395
  • 32
  • 113
  • 196
rectangletangle
  • 50,393
  • 94
  • 205
  • 275

2 Answers2

5

The following option instructs the window manager not to decorate the window (i.e no title bar and window buttons, plus no borders)

root.overrideredirect(True)

A false argument restores the decorations.

nbro
  • 15,395
  • 32
  • 113
  • 196
tzot
  • 92,761
  • 29
  • 141
  • 204
  • 1
    You might add that, with this technique you can draw whatever borders you want. Place a canvas so that it fills the frame then draw whatever you want. – Bryan Oakley May 12 '11 at 11:11
  • Thanks, I'm already aware of this method. It works, however I'm trying to go for a completely native look. – rectangletangle May 12 '11 at 21:31
3

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?

nbro
  • 15,395
  • 32
  • 113
  • 196
malkia
  • 1,389
  • 13
  • 12