tkinter:如何对齐一组文本长度不同的单选按钮 [英] tkinter: how to align a set of radio buttons that differs in text length

查看:29
本文介绍了tkinter:如何对齐一组文本长度不同的单选按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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')

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

I have this section of code for a set of radio button in my project, and it looks like this when I run it:

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

I would like to anchor them all to the west so their left side would be align vertically. I tried to use tk instead of ttk(since there is no anchor option in ttk) radiobutton and set anchor = 'w', but they still looks like this:

有人可以帮忙吗?TIA

Could some one please help? TIA

推荐答案

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

never mind, I found it out. I should have done anchor = 'w' when packing. So something like:

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')

这篇关于tkinter:如何对齐一组文本长度不同的单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆