Computer >> คอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

จะวางหน้าต่าง Tkinter ไว้ด้านบนของหน้าต่างอื่นได้อย่างไร?


เมื่อใดก็ตามที่เราสร้างโปรแกรม GUI โดยทั่วไป tkinter จะแสดงหน้าจอเอาต์พุตในพื้นหลัง กล่าวอีกนัยหนึ่ง tkinter จะแสดงหน้าต่างโปรแกรมด้านหลังโปรแกรมอื่นๆ เพื่อให้หน้าต่าง tkinter อยู่เหนือหน้าต่างอื่น เราจำเป็นต้องใช้ attributes('- topmost',True) คุณสมบัติ. มันดึงหน้าต่างขึ้นด้านบน

ตัวอย่าง

#Importing the library
from tkinter import *

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

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

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

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

win.mainloop()

ผลลัพธ์

การเรียกใช้โค้ดข้างต้นจะทำให้หน้าต่างอยู่ด้านบนสุดของหน้าต่างอื่นๆ ทั้งหมด -

จะวางหน้าต่าง Tkinter ไว้ด้านบนของหน้าต่างอื่นได้อย่างไร?