3

a question following the one asked in How to make a Tkinter window jump to the front?

I'd like to have a toplevel window (which I use to navigate my other main window) always on the front. BUT I'd like it to be on the front only relative to all the various windows of my tkinter program.

The chwin.wm_attributes("-topmost",True) solution, instead, forces this window on top of every window in my desktop (at least here: Linux fedora13).

Do you know of any other solution?

Community
  • 1
  • 1
alessandro
  • 3,838
  • 8
  • 40
  • 59

2 Answers2

4

At the end the lift() method call did not work well. When I use it and I cover the window I want to remain on top, this call just lets the icon of the window to be highlighted in the taskbar (as it happens when you have some action in a non visible window), but the window is not lifted.

A Linux glitch? I dont know

I finally discovered a way to do it: just call wm_transient from the window that has to stay on top:

secondarywindow.wm_transient(root)

This way, secondarywindow is always above root, but it can be obscured by any other programs I'm using on the desktop

alessandro
  • 3,838
  • 8
  • 40
  • 59
1

You could lift the window you want after each creation of a new window:

import Tkinter as tk
root = tk.Tk()
tk.Label(root, text="I'm the root").grid()
main = tk.Toplevel(root)
tk.Label(main, text="I'm the one you want").grid()
def bring_to_front():
    """This function was made to demonstrate"""
    tk.Toplevel(root)
    # Each time a new window is created, lift the one you want above it.
    main.lift()
    root.after(5000, bring_to_front)
root.after(1, bring_to_front)
root.mainloop()

Notice how the window you want always retains focus (is on top) regardless of how many Toplevels are made. Nevertheless, it will not raise above other applications (only the windows made by the script).

You could even use the iconify method of Toplevel to minimize every window you don't want on top right now.

Note that I worte this in Python 2.7. If you do not have/use Python, just apply the principles given in this script elsewhere.