Home > other >  Storing Tuple as a Variable (QComboBox)
Storing Tuple as a Variable (QComboBox)

Time:12-07

My project has multiple combobox drop downs, where the user's selection of the first drop down dictates the output of the next.

Example:

first_dropdown = 'Colored Pencil'
colors = "Black", "Blue", "Brown", "Green", "Grey", "Yellow", "White"

self.example = QComboBox()
self.example.addItem(first_dropdown, [colors])

When I do this, I get the following error:

TypeError: index 0 has type 'tuple' but 'str' is expected

The program executes without errors if instead of using the variable 'colors', I simply list the entire tuple ("Black", "Blue", etc.)

How can I store the tuple as a variable and still use it in my program? Is this possible?

Thank you!

CodePudding user response:

When you do this:

[colors]

you would get this:

[('Black', 'Blue', 'Brown', 'Green', 'Grey', 'Yellow', 'White')]

the function needs a tuple made of strings not a list of a tuple of strings. you can do a simple fix by writing:

tuple(colors)
  • Related