When to use pack or grid layouts in tkinter?

后端 未结 3 1110
灰色年华
灰色年华 2020-12-29 20:53

Are there any best practice tips regarding when one should use pack vs. grid for their layouts?

From what I\'ve been reading via google, the concencus seems to be th

3条回答
  •  滥情空心
    2020-12-29 21:19

    I always recommend grid over pack for polished applications. There are only a few edge cases where pack is easier and fits the bill (everything in one row or col). grid has better "composability" (e.g. megawidgets or gridding elements of gridded elements). The reasons to prefer grid are the extra fine-tuning options that it provides. The use of weight (which effects growing and shrinking btw), minsize and maxsize, as well as convenience features like enforcing uniform rows/columns.

    A fully gridded app of any size will use (significantly) fewer frames than an equivalent packed app, and have better shrink/expand control over inner elements.

    BTW, both pack and grid can show/hide sub-elements, though the syntax differs slightly between the two. Grid is just slightly better because 'remove' (rather than 'forget') will remember the grid options on the slave widget.

提交回复
热议问题