Tkinter มีฟีเจอร์ ฟังก์ชัน และเมธอดในตัวมากมายสำหรับสร้าง GUI ของแอปพลิเคชัน จำเป็นต้องรู้ว่าจะตั้งค่าตำแหน่ง widget อย่างไร เพื่อให้ตอบสนอง (responsive) ได้ดี
Tkinter มี geometry managers สำหรับตั้งค่าตำแหน่ง elements และ widgets Geometry manager Place ใช้สำหรับตั้งค่าตำแหน่ง widget ที่ซับซ้อน
ตัวอย่าง
สมมติต้องการให้ widget อยู่มุมล่างขวาของหน้าต่าง ใช้ place geometry manager พร้อมคุณสมบัติ anchor
# Import the required libraries
from tkinter import *
from tkinter import ttk
# Create an instance of tkinter frame or window
win=Tk()
# Set the size of the window
win.geometry("700x350")
# Add buttons in the frame
button1=ttk.Button(win, text="Button-1")
button1.place(rely=1.0, relx=1.0, x=0, y=0, anchor=SE)
win.mainloop()
ผลลัพธ์
รันโค้ด จะวาง widget ที่มุมล่างขวาของหน้าต่าง
