ttk.Separator set the length/width

前端 未结 1 1001
我寻月下人不归
我寻月下人不归 2021-01-20 04:54

How to set/change the length/width of a ttk.Separator object in Tkinter?

        ttk.Separator(self, orient=\'horizontal\').grid(column=0,
        row=0, col         


        
相关标签:
1条回答
  • 2021-01-20 05:20

    Your problem is not that the separators are too short, it's that you haven't told grid what to do with extra un-allocated space. Your columns are only exactly as wide as they need to be, and your separator is only as wide as the columns it is in. In a comment you say "I want them to go till the end of the entry fields" and that's exactly what they are doing. What you really want is for all of the entry fields to end at the same location.

    The quick fix is to make sure that when you use grid, you always give at least one row and one column a non-zero weight. This tells grid where to allocate any extra space. In your case you haven't done this, so in the third row there is space that does unused to the right of the entry widget.

    The quick and dirty solution here is to make sure that either column 0 or 1 gets the extra space. Usually the choice is to give it to the input widget. So, you can add this to improve the situation:

    thirdLayer.grid_columnconfigure(1, weight=1)
    

    This solves the immediate problem, but you need to do the same thing for every one of your frames, as well as for the root window. For every frame that contains children managed by grid, you need to give at least one row and one column a weight.

    Since you seem to be trying to create a grid of labels and entry widgets, you might want to consider using a single frame rather than multiple frames. By using a single frame you don't have to try to guess how much padding to use to get everything to line up.

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