简体   繁体   中英

Always keep a widget on top of the others in tkinter

Is there any way to always keep a widget on top of the others in tkinter?

Here's the code:

from tkinter import *

root = Tk()

button_1 = Button(root , text = "Button 1")
button_1.grid(row = 0 , column = 0)

button_2 = Button(root , text = "Button 2")
button_2.grid(row = 0 , column = 0)

mainloop()

Here, I positioned button_1 and button_2 in the same row, but the problem is that, as I defined button_2 after defining button_1 , button_2 stays on top of button_1 .

What I want is that button_1 should always be on top of the other widgets in the window.

Is there any way to achieve this in tkinter?

It would be great if anyone could help me out.

Use the .lift()

from tkinter import *

root = Tk()

button_1 = Button(root , text = "Button 1")
button_1.grid(row = 0 , column = 0)

button_2 = Button(root , text = "Button 2")
button_2.grid(row = 0 , column = 0)

button_1.lift()

mainloop()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM