Filling screen X with grid in Tkinter?

后端 未结 1 1885
南笙
南笙 2021-01-23 13:32

I was wondering if any of you Tkinter experts out there could help me with a question, do any of you know if there is a alternative to packs fill=X or fill=Y commands for grids?

相关标签:
1条回答
  • 2021-01-23 13:45

    Use the sticky attribute to make objects fill the row and/or column that they are in.

    Apply a weight to the rows and/or columns to get them to use any extra space in the container using grid_rowconfigure and grid_columnconfigure. The "weight" defines how grid will allocate any extra space once all the children are arranged. By default, rows and columns have zero weight, meaning they don't use any extra space.

    For example:

    frame = tk.Frame(...)
    l1 = tk.Label(frame, ...)
    l2 = tk.Label(frame, ...)
    l1.grid(row=0, column=0, sticky="nsew")
    l2.grid(row=1, column=1, stickky="nsew")
    frame.grid_rowconfigure(0, weight=1)
    frame.grid_columnconfigure(0, weight=1)
    
    0 讨论(0)
提交回复
热议问题