Grouping windows in tkinter
Asked Answered
F

1

3

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.

Flanigan answered 29/11, 2016 at 19:47 Comment(0)
S
4

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)

Snake answered 30/11, 2016 at 16:35 Comment(2)
This worked! It turns out the WM_CLASS wasn't what I needed. Please add to your answer that in tkinter, you need to do top_level.group(root), where top_level is the Toplevel, and root is your Tk instance. Thanks!Flanigan
Edited it myself, actually.Flanigan

© 2022 - 2024 — McMap. All rights reserved.