Search code examples
tkinteroptionmenu

How could I make OptionMenu for 10 options with the same choices using a for loop and get the values using Tkinter?


This is what I have tried so far:

choices = ['True', 'False']
self.dd = StringVar()
for i in range(k):
OptionMenu(root, self.dd, *choices).grid(row=i+6, column=2, sticky=W)

When I make a choice for one option, that choice is selected for all options.


Solution

  • Each OptionMenu needs its own instance of StringVar

    self.vars = []
    for i in range(k):
        var = StringVar()
        OptionMenu(root, var, *choices)
        self.vars.append(var)