Multiple ComboBoxes in Tkinter Python

后端 未结 1 1995
鱼传尺愫
鱼传尺愫 2021-01-25 12:48

I\'m trying to generate multiple ComboBoxes with values from a \"config.ini\" file, the config.ini file data is:

priority1 = Normal:farty-blobble-fx.wav:2
priority8

相关标签:
1条回答
  • 2021-01-25 13:49

    The problem is that you're creating more than one combobox, yet you keep overwriting the variables in each iteration of the loop. At the end of the loop, self.PRIOR_SOUNDS will always point to the last combobox that you created. The same is true for self.box_value, self.PLAY, etc.

    The simplest solution is to use an array or dictionary to store all of your variables. A dictionary lets you reference each widget or variable by name; using a list lets you reference them by their ordinal position.

    A solution using a dictionary would look something like this:

    self.combo_var = {}
    self.combo = {}
    for name, value in parser.items(section_name):
        ...
        self.combo_var[name] = StringVar()
        self.combo[name] = Combobox(..., textvariable = self.combo_var[name])
        ...
    
    0 讨论(0)
提交回复
热议问题