tkinter:如何对齐一组文本长度不同的单选按钮

编程入门 行业动态 更新时间:2024-10-28 15:24:26
本文介绍了tkinter:如何对齐一组文本长度不同的单选按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..
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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-30 06:32:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1390870.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:单选   长度   按钮   文本   tkinter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!