Python Tkinter将单选按钮向西对齐 [英] Python tkinter align radio buttons west

查看:85
本文介绍了Python Tkinter将单选按钮向西对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在以文本形式阅读Python脚本,并使用其中编写的argparse方法使用tkinter自动创建GUI.除了我的单选按钮之外,所有这些都可以正常工作,由于某种原因,我不能强制在大列中向西/向左对齐.他们只是坐在它的中间

I'm reading a Python script in as text and using the argparse methods written within it to create GUIs automatically using tkinter. It all works fine apart from my radio buttons which I can't force to align west / left within a large column for some reason. They just sit in the middle of it

我的整个代码使用网格,而不是打包,我宁愿不更改它.

My entire code uses grid, not pack, and I'd rather not change it.

def create_radiobuttons(self,
                        arg):
    """Creates a widget that will only accept one option
    """

    ttk.Label(self.mainframe, text=arg['metavar']).grid(column=0, row=self.num, sticky=(N, E))
    var = StringVar()
    for choice in arg['choices']:
        box = Radiobutton(self.mainframe, text=choice, variable=var, value=choice, width=self.width)
        box.grid(column=1, row=self.num, anchor=W)
        self.num += 1
    self.display_help(arg)

    return box

谢谢!

推荐答案

anchor 属性与单选按钮一起使用,因此按钮的内容固定在小部件的左侧.

The anchor attribute goes with the radiobutton, so that the contents of the button are anchored to the left side of the widget.

根据此列的管理方式,您可能还需要在调用 grid 时添加 sticky 属性,以使小部件作为一个整体粘在左侧列所在的列.

Depending on how this column is managed, you may also need to add the sticky attribute when calling grid, so that the widget as a whole sticks to the left side of the column it is placed in.

这篇关于Python Tkinter将单选按钮向西对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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