【问题标题】:tkinter: how to align a set of radio buttons that differs in text lengthtkinter:如何对齐一组文本长度不同的单选按钮
【发布时间】:2017-05-05 01:38:52
【问题描述】:
tech_radioButton1 = ttk.Radiobutton(selection_frame_1, text="ANT+", variable = self.tech_var, value = 1, command = self.tech_select)
tech_radioButton1.pack(side = 'top')
tech_radioButton2 = ttk.Radiobutton(selection_frame_1, text="Bluetooth", variable = self.tech_var, value = 2, command = self.tech_select)
tech_radioButton2.pack(side = 'top')
tech_radioButton3 = ttk.Radiobutton(selection_frame_1, text="BTLE", variable = self.tech_var, value = 3, command = self.tech_select)
tech_radioButton3.pack(side = 'top')
tech_radioButton4 = ttk.Radiobutton(selection_frame_1, text="WLAN", variable = self.tech_var, value = 4, command = self.tech_select)
tech_radioButton4.pack(side = 'top')
tech_radioButton5 = ttk.Radiobutton(selection_frame_1, text="UNII", variable = self.tech_var, value = 5, command = self.tech_select)
tech_radioButton5.pack(side = 'top')

我的项目中有一组单选按钮的这段代码,当我运行它时它看起来像这样:

我想将它们全部锚定在西边,这样它们的左侧就会垂直对齐。我尝试使用 tk 而不是 ttk(因为 ttk 中没有锚选项)单选按钮并设置锚 = 'w',但它们仍然看起来像这样:

有人可以帮忙吗? TIA

【问题讨论】:

    标签: python tkinter


    【解决方案1】:

    没关系,我发现了。我应该在打包时做 anchor = 'w' 。所以像:

    tech_radioButton1 = ttk.Radiobutton(selection_frame_1, text="ANT+", variable = self.tech_var, value = 1, command = self.tech_select)
    tech_radioButton1.pack(side = 'top', anchor = 'w')
    tech_radioButton2 = ttk.Radiobutton(selection_frame_1, text="Bluetooth", variable = self.tech_var, value = 2, command = self.tech_select)
    tech_radioButton2.pack(side = 'top', anchor = 'w')
    tech_radioButton3 = ttk.Radiobutton(selection_frame_1, text="BTLE", variable = self.tech_var, value = 3, command = self.tech_select)
    tech_radioButton3.pack(side = 'top', anchor = 'w')
    tech_radioButton4 = ttk.Radiobutton(selection_frame_1, text="WLAN", variable = self.tech_var, value = 4, command = self.tech_select)
    tech_radioButton4.pack(side = 'top', anchor = 'w')
    tech_radioButton5 = ttk.Radiobutton(selection_frame_1, text="UNII", variable = self.tech_var, value = 5, command = self.tech_select)
    tech_radioButton5.pack(side = 'top', anchor = 'w')
    

    【讨论】:

      猜你喜欢
      • 2021-01-20
      • 2017-01-28
      • 2015-12-27
      • 2017-01-16
      • 2016-08-28
      • 2021-08-23
      • 2016-05-11
      • 2023-02-26
      • 1970-01-01
      相关资源
      最近更新 更多