Tkinter Frame Background Disappear When I Associate A Label To It
Solution 1:
Frames typically "shrink to fit" their contents unless there's a constraint put on the frame. This is normal, expected, and usually desirable. So, the left frame will request that it is just wide enough to fit the label, and just tall enough to fit the label. The frames in the other columns, because they have no children, will be the size that you request.
So, you have one column that wants to be as wide and as tall as the label, and two other columns that want to be 200 pixels wide. You have one row that wants to be tall enough to fit everything, which means it is as tall as the tallest widget, or 200 pixels. This ends up leaving extra space in the leftmost column.
Without specifying any options, each row will be as tall as the tallest widget in the row, in this case 200 pixels. Each column will be as wide as the widest widget. The leftmost column wants to be the width of the frame, which itself wants to be only as wide as the label. So, the leftmost column will be only as wide as the label. The other columns will be 200 pixels wide because that's what you told them to be.
Now, you want the green frame to fill the cell that it is in. In your case you haven't asked that the frame fill the space allotted so it shrinks to fit. You need to add the sticky
option to the frame to force it to "stick" to all four edges of the space it was given.
leftFrame.grid(row=1, column=0, sticky="nsew")
Of course, you'll have the same problems with the other frames as well, assuming you plan to put widgets in them.
Post a Comment for "Tkinter Frame Background Disappear When I Associate A Label To It"