Hello,
I'm trying to populate 22 combo boxes with the same options (I have 'Material_1_ComboBox' all the way to 'Material_22_ComboBox') and I want to know how to do populate all those combo boxes with my 'stringMaterialList' using a for loop instead of going:
How would I go about doing that?
the part that I'm having trouble with is thinking about how I would iterate through the names so it just changes the number in the middle, therefore populating all 22 ComboBoxes.
Thanks in advance.
Snippet
I'm trying to populate 22 combo boxes with the same options (I have 'Material_1_ComboBox' all the way to 'Material_22_ComboBox') and I want to know how to do populate all those combo boxes with my 'stringMaterialList' using a for loop instead of going:
self.Material_1_ComboBox.addItems(StringMaterialList) self.Material_2_ComboBox.addItems(StringMaterialList) self.Material_3_ComboBox.addItems(StringMaterialList) ... ... self.Material_22_ComboBox.addItems(StringMaterialList)
How would I go about doing that?
the part that I'm having trouble with is thinking about how I would iterate through the names so it just changes the number in the middle, therefore populating all 22 ComboBoxes.
Thanks in advance.
Snippet
#------------------------------------------
# Material Dropdown
#------------------------------------------
#Connect to the Inventory database
connection = sqlite3.connect(InventoryDatabase)
cursor = connection.cursor()
cursor.execute('''
SELECT Name From Items
''')
connection.commit()
#Get the Categories from the Database
MaterialList = cursor.fetchall()
#Convert the SQL Results to a String List
from itertools import chain
StringMaterialList = list(chain.from_iterable(MaterialList))
#Close the connection
connection.close()
#Add the SQL Results to the Dropdown List
self.Material_1_ComboBox.addItems(StringMaterialList)
#------------------------------------------
