How to deiconify and raise Tk window when using GNOME as desktop environment

71 views Asked by At

The program below creates a window that contains a button. When the button is clicked, the window is iconified (minimized). After 3000 milliseconds, the window is supposed to deiconify and raise itself above all other windows. When I run the program in the GNOME desktop environment using wish mywindow.tk, the window iconifies as expected when the button is clicked. However, it does not deiconify and does not raise itself above all other windows after 3 seconds. There are no error messages.

proc doSomething {} {
    wm iconify .
    after 3000 {
        wm deiconify .
        raise .
    }
}

button .mybutton -text "Click me" -command doSomething
grid .mybutton

What is the cause of the problem? How do I deiconify a window in Tk and raise it above all others when using the GNOME desktop environment?

  • Tcl/Tk version: 8.6.13
  • GNOME Shell version: 43.6
  • I am using GNOME on Xorg instead of GNOME on Wayland.
  • OS: Debian 12 bookworm
2

There are 2 answers

0
Flux On BEST ANSWER

I managed to deiconify and raise the window above all others by withdrawing the window right before deiconifying it:

proc doSomething {} {
    wm iconify .
    after 3000 {
        wm withdraw .
        wm deiconify .
    }
}

button .mybutton -text "Click me" -command doSomething
grid .mybutton

According to the Tk documentation for wm wihdraw:

Note: it sometimes seems to be necessary to withdraw a window and then re-map it (e.g. with wm deiconify) to get some window managers to pay attention to changes in window attributes such as group.

0
Donal Fellows On

There isn't anything you can do about it. Tk does window deiconifying and raising (of toplevels) by asking the window manager to do it, but the window manager is entitled to ignore the request. The low-level API for that works that way, and window managers often prefer to ignore requests that they don't believe correspond directly to real user activity.

Internal Tk widgets can be directly restacked; Tk always handles those calls itself.

Sorry about that. This isn't a Tk problem as such, but rather window manager policy.