![]() ![]() ![]() Since it's not clear exactly what your problem is based on your description, the above solution is probably the simplest for you. Of course, you can also place the checkbuttons in separate columns - which is often easiest - but you might need to have other items in other rows span multiple columns and deal with column weights. After you create a table you can adjust the widths of columns by dragging their borders with the mouse and by setting their widths to absolute or percentage values. View.pack(side="top", fill="both", expand=True) By default, the widths of all columns in tables are 'dynamic' they expand to fit the width of the content they contain and the defined width of the table. # with the window, but that the checkbuttons # window, so you can see that the column grows # let column 1 expand and contract with the # packed in a frame, they will always be "stuck"Ĭid(row=2, column=1, sticky="w") # place our frame of checkbuttons in the same column # will force column 2 to be widget than a checkbutton # this entry is for illustrative purposes: it Here is a working example base on python 2.7: import Tkinter as tkĬb1 = tk.Checkbutton(cbframe, text="Choice 1")Ĭb2 = tk.Checkbutton(cbframe, text="Choice 2")Ĭb3 = tk.Checkbutton(cbframe, text="Choice 3")Ĭb1.pack(side="left", fill=None, expand=False)Ĭb2.pack(side="left", fill=None, expand=False)Ĭb3.pack(side="left", fill=None, expand=False) You can put whatever you want in that inner frame, but from the perspective of the grid there is only a single widget in each cell of the grid. You're only putting one widget in a cell: the frame. Note that this solution doesn't break the rule of thumb I mentioned earlier. Then, no matter how big the window gets, the checkbuttons will always be stuck to the left side of their containing frame. Then, put the frame in your grid with sticky="w". Put all of your checkbuttons in a frame and pack them on the left side of that frame. The simplest solution for you is to combine grid and pack. A general rule of thumb is that you should never put more than one widget in a cell. There's absolutely no reason to resort to such a solution. That, or elsewhere in your code you give a non-zero weight to some of those columns that is causing them to expand.īefore I talk about a solution, let me make sure it's clear that the way you're using grid to put more than one widget in the same cell is definitely the wrong way to do it. For example, here are two grid layouts that apply to every device and viewport, from xs to xl.Add any number of unit-less classes for each breakpoint you need and every column will be the same width. The column will default to the smallest width that will accomodate the widest item. Utilize breakpoint-specific column classes for easy column sizing without an explicit numbered class like. The behavior you describe where there is too much space between the elements is probably due to the fact you have other widgets in that same column which are wider. The default behavior of using the grid geometry manager is that columns will be as small as possible, so you don't need to do anything (assuming you're using grid properly). ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |