เพื่อวางวัตถุกึ่งกลาง frame ใช้เมธอด place ตัวอย่างนี้แสดงวิธีหาพิกัดของ Toplevel window
ขั้นตอน
นำเข้าไลบรารี สร้าง instance ของ tkinter frame
กำหนดขนาด frame ด้วย win.geometry
สร้างปุ่มและ label
ตั้งตำแหน่งปุ่มด้วย place method ส่งพิกัด x และ y
วางกึ่งกลาง widget ที่ตำแหน่งสัมพัทธ์ x และ y 0.5 (relx=0.5, rely=0.5) ตั้ง anchor กึ่งกลาง anchor=CENTER
รัน mainloop
ตัวอย่าง
from tkinter import *
from tkinter import ttk
win = Tk()
win.geometry("750x350")
win.title("Main Window")
def toplevel_position():
print("The coordinates of Toplevel window are:", top.winfo_x(), top.winfo_y())
top = Toplevel(win, height=150, width=300)
top.title("This is the Toplevel Window")
top.attributes('-topmost', 'true')
button = ttk.Button(top, text="Get position", command=toplevel_position)
button.place(relx=0.5, rely=0.5, anchor=CENTER)
top.mainloop()
ผลลัพธ์

คลิก "Get position" จะพิมพ์พิกัด Toplevel window บนคอนโซล:
The coordinates of Toplevel window are: 282 105