How to create equal-width columns in Python 2.7 with Tkinter

后端 未结 1 1357
粉色の甜心
粉色の甜心 2020-11-29 12:17

How can I force the columns in a Tkinter application window to be of equal width?

The tkdocs website states as follows:

The width of each column
相关标签:
1条回答
  • 2020-11-29 13:12

    To make a gridded layout have all columns have the same width, you've got to configure those columns to have the same weight and to be in the same uniform group. This configuration is associated with the master widget, not any of the contained widgets (because columns can contain many widgets, of course).

    In standard Tk, this is done with:

    # "fred" is just some arbitrary key; it means nothing other than to name the group
    grid columnconfigure $master 0 -weight 1 -uniform fred
    

    In Tkinter (note that uniform seems to be not documented in the docstring but it is exactly what you need):

    # "fred" is just some arbitrary key; it means nothing other than to name the group
    master.grid_columnconfigure(0, weight=1, uniform="fred")
    

    Then repeat for the other column indices that you want to set things for. (As you can see, the code's very similar in these two cases.)

    0 讨论(0)
提交回复
热议问题