Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grouping windows in tkinter

I have a tkinter application that has a main window (a Tk) and an additional window (a Toplevel).

I want these windows to group together in the window manager (GNOME Shell). I believe it is necessary to have both the WM_CLASS resource and the WM_CLASS name to be set the same for both windows in order for this to happen.

Setting className on Tk and setting class on Toplevel to my application name seems to change the WM_CLASS name but not the resource, which is why I think they're not grouping. xprop WM_CLASS on the windows shows my chosen name for both entries on the Tk: WM_CLASS(STRING) = "myapp", "Myapp". For the Toplevel, it shows a tk_uid for the first element: WM_CLASS(STRING) = "140626444609872", "Myapp".

I also tried setting the titles of the windows, but it seemed to make no difference.

like image 536
Jim Hunziker Avatar asked Feb 23 '26 19:02

Jim Hunziker


1 Answers

You can use the wm group command to group windows together. Some operating systems / window managers may not respect this setting.

In tkinter, you can do this by calling group on the Toplevel instance with the root Tk instance as an argument.

References: wm (tk), wm (tkinter)

like image 134
Brad Lanam Avatar answered Feb 25 '26 08:02

Brad Lanam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!