Tkinter ระดับบนสุด คลาสมี ระดับบนสุด หน้าต่างที่เป็นหน้าต่างลูกอื่นที่ไม่ใช่หน้าต่างหลัก เมื่อใดก็ตามที่เราสร้างหน้าต่างระดับบนสุด หน้าต่างจะปรากฏขึ้นเหนือหน้าต่างหลักพร้อมกับวิดเจ็ตที่กำหนดไว้
เพื่อให้หน้าต่างระดับบนสุดโฟกัสได้ เราสามารถใช้ grab_set() กระบวนการ. โดยจะรักษาหน้าต่างระดับบนสุดไว้เหนือหน้าต่างอื่นๆ เสมอ
ตัวอย่าง
#Import the tkinter library
from tkinter import *
#Create an instance of tkinter frame
win = Tk()
win.geometry("700x350")
def open_win():
top = Toplevel(win)
top.geometry("700x250")
Label(top, text= "Hey Folks!", font= ('Helvetica 14 bold')).pack()
top.grab_set()
#Create a Label to print the Name
label= Label(win, text="Click the below Button to open the Popup", font= ('Helvetica 18 bold'))
label.pack(pady= 30)
#Create a Button
button= Button(win, text= "Click Me", command= open_win, font= ('Helvetica 14 bold'), foreground= 'OrangeRed3', background= "white")
button.pack(pady=50)
win.mainloop() ผลลัพธ์
การเรียกใช้โค้ดด้านบนจะแสดงหน้าต่างที่มีปุ่มสำหรับเปิดหน้าต่างป๊อปอัป

ตอนนี้ ให้คลิกปุ่มเพื่อเปิดหน้าต่างป๊อปอัป
