Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Python

widget.rowconfigure hay widget.grid_rowconfigure trong Tkinter?


Cả widget.rowconfigure() và widget.grid_rowconfigure() đều dùng để cấu hình trọng số (weight) cho hàng trong Grid Geometry Manager, cho phép hàng co giãn. Chúng thực chất là cùng một phương thức, rowconfigure là alias ngắn gọn.

Ví dụ minh họa

from tkinter import *

win = Tk()
win.geometry("700x350")

f1 = Frame(win, background="bisque", width=10, height=100)
f2 = Frame(win, background="blue", width=10, height=100)

f1.grid(row=0, column=0, sticky="nsew")
f2.grid(row=0, column=1, sticky="nsew")

win.columnconfigure(0, weight=1)
win.rowconfigure(1, weight=0)

win.mainloop()

Kết quả đầu ra

Hai khung màu chia cột, cột 0 có weight=1 mở rộng.

widget.rowconfigure hay widget.grid_rowconfigure trong Tkinter?