Filling screen X with grid in Tkinter?

你离开我真会死。 提交于 2020-11-29 10:23:06

问题


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? Or some code that would add in this function? (I have searched around for a bit and couldn't find anything)


回答1:


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)


来源:https://stackoverflow.com/questions/32555496/filling-screen-x-with-grid-in-tkinter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!