在 tkinter 裡 grid 區塊如何對齊的方式。直接調整 .grid() 裡的屬性 sticky = W, sticky = E, sticky = N。我試了發現 W 會等於 LEFT, E=RIGHT, N=Center. default 值是 N.
Normally to accomplish what you are after you would simply put sticky = W in the grid options for the Entry widget to left-justify the contents of the cell. However, this will only work for each individual Frame, leaving the contents of each separate LabeledFrame out of alignment.
Easiest way to fix this without changing much code:
You’ll want to add a line to your for loop. If you specify a large minimum-width of the column that self.field’s Frame is inserted into, you can be sure that things will align how you want them to. I’ve also added config options to the grid calls within the LabeledEntry class: sticky = W for the Label & sticky = E for the Entry.