如何讓 Tkinter 視窗跳轉到最上面?


為了讓 Tkinter 視窗或根視窗跳到所有其它視窗上面,我們可以使用 attributes 方法,其通常需要兩個值,指定“置頂”值,另一個是布林值。

示例

#Importing the library
from tkinter import *

#Create an instance of tkinter window or frame
win= Tk()

#Setting the geometry of window
win.geometry("600x250")

#Create a Label
Label(win, text= "Hello Everyone!",font=('Helvetica bold',
15)).pack(pady=20)

#Make the window jump above all
win.attributes('-topmost',1)

win.mainloop()

輸出

執行上述程式碼將使視窗停留在所有其它視窗上面,

更新於: 26-Mar-2021

2K+ 瀏覽

啟動您的 職業

完成課程即可獲得認證

開始
廣告
© . All rights reserved.