accelerate
accelerate

Reputation: 51

Radiobutton only shows one option

I'm not sure what I'm doing wrong, but it seems that my radiobutton only shows one option instead of two options(which is what I originally wanted).

PLAYERS = [("Black", "black"),
           ("White", "white")]

def first_player(self) -> str:

    self.firstplayer = tkinter.StringVar(value = 'black')

    self._player_text = tkinter.StringVar()

    self._player_text.set('Which player moves first: ')

    player_label = tkinter.Label(
            master = self.root_window, textvariable = self._player_text,
            background = 'yellow', height = 1, width = 20, font = DEFAULT_FONT)

    player_label.grid(row=1, column = 0, padx = 10, pady=90, sticky = tkinter.W+tkinter.N)

    for text,mode in PLAYERS:
        first = tkinter.Radiobutton(self.root_window, text = text,
                            variable = self.firstplayer , value = mode)

        first.grid(row = 1, column = 0, padx = 300, pady = 90, sticky = tkinter.W + tkinter.N)

    return self.firstplayer.get()

Upvotes: 0

Views: 44

Answers (1)

Bryan Oakley
Bryan Oakley

Reputation: 385800

You are placing both radiobuttons in the same place: row 1, column 0. The first one it thus invisible because it is under the second one. If you want the label and two radiobuttons on the same row but different columns, the solution is to give them all the same row, and different columns.

There are many ways to accomplish this, I'll show you one:

column = 1
for text,mode in PLAYERS:
    first = tkinter.Radiobutton(self.root_window, text = text,
                                variable = self.firstplayer , value = mode)
    first.grid(row = 1, column = column, sticky = tkinter.W + tkinter.N)
    column += 1

Upvotes: 2

Related Questions