Có cách đặt widget Tkinter trong cửa sổ. Geometry manager có ba phương thức pack(), place() và grid(). Mỗi cách có ưu/nhược điểm. Để đặt vị trí nút, ưu tiên place(x, y) nhận tọa độ x, y.
Ví dụ
Mã mẫu chứa nút dùng place(x, y) đặt giữa cửa sổ.
# Import Tkinter library
from tkinter import *
from tkinter import ttk
# Tạo instance Tkinter frame
win = Tk()
# Đặt geometry
win.geometry("750x250")
def close_win():
win.destroy()
# Tạo Buttons
button = ttk.Button(win, text="Click", command=close_win)
button.place(x=325, y=125)
#Tạo Label
Label(win, text="Click the Button to Close the Window", font=('Consolas 15')).pack()
win.mainloop()
Kết quả
Chạy mã hiển thị cửa sổ nút ở giữa cửa sổ.
