Tom Boy
Tom Boy

Reputation: 659

How to make Toplevel() widget appear above main root window?

I have made a Toplevel widget but when it pops up it always appears below my root window. Is there an easy way I can make it come to the top most level when it pops up?

Upvotes: 2

Views: 3194

Answers (2)

andsa
andsa

Reputation: 241

try attributes

import tkinter

root = tkinter.Tk()
root.title("root")

top = tkinter.Toplevel(root)
top.attributes('-topmost', 'true')
top.title("top")

root.mainloop()

Upvotes: 1

Tadhg McDonald-Jensen
Tadhg McDonald-Jensen

Reputation: 21453

you can use the .lift() method on a Toplevel widget:

import tkinter

root = tkinter.Tk()
root.title("root")

top = tkinter.Toplevel(root)
top.title("top")
top.lift(root)
root.mainloop()

according to this documentation you should be able to just use top.lift() to raise above all other windows but it didn't seem to work for me.

Edit: calling top.lift() without arguments does work when called during the mainloop, although since this question was specifically when starting the program that isn't very useful.

Upvotes: 4

Related Questions