tcltk-toolkitgnomexorggnome-shell

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


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

Solution

  • 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.