Jim Hunziker Jim Hunziker - 3 days ago 6
Python Question

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.

Answer

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)

Comments