为什么Python Tkinter单选按钮向左对齐?

Why do Python Tkinter Radio Buttons align left?

我的单选按钮有对齐问题。我想要三列表单元素。由于某种原因,当我在表单中添加单选按钮时,它们似乎占据了左侧新列的空间。我希望每个单元具有相同大小的简单网格布局。事实并非如此。任何建议将不胜感激!

Radio Button Alignment

这是我的代码的一部分:

1
2
3
4
5
6
7
8
9
10
11
12
13
    self._mode_state = StringVar()
    self._mode_radio_timelapse = Radiobutton(self, text="Timelapse", command=self._transition(), value=self._timelapse_mode, variable=self._mode_state)
    self._mode_radio_continuous = Radiobutton(self, text="Continuous", command=self._transition(), value=self._continuous_mode, variable=self._mode_state)
    self._mode_radio_ramphold = Radiobutton(self, text="Ramp and Hold", command=self._transition(), value=self._ramp_hold_mode, variable=self._mode_state)
    self._mode_radio_timelapse.grid(row=0, column=0, pady=10)
    self._mode_radio_continuous.grid(row=0, column=1, pady=10)
    self._mode_radio_ramphold.grid(row=0, column=2, pady=10)

    image_set_label = Label(text="Image Set Type:")
    image_set_label.grid(row=1, column=0, pady=10)
    self._image_set_type = Entry()
    self._image_set_type.insert(0,"Ramp")
    self._image_set_type.grid(row=1, column=1, pady=10, columnspan=2)


窗口小部件并非全部在同一网格上。单选按钮特别是用self的父级设置的,但是LabelEntry小部件不是用任何父级创建的,因此父级默认为根对象。

解决方法:

1
2
3
4
5
image_set_label = Label(self, text="Image Set Type:") # made self parent
image_set_label.grid(row=1, column=0, pady=10)
self._image_set_type = Entry(self) # made self parent
self._image_set_type.insert(0,"Ramp")
self._image_set_type.grid(row=1, column=1, pady=10, columnspan=2)