WRJ
WRJ

Reputation: 667

Python tkinter align radio buttons west

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

Thanks!

Upvotes: 0

Views: 3275

Answers (1)

Bryan Oakley
Bryan Oakley

Reputation: 386230

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

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.

Upvotes: 3

Related Questions