Aug-01-2022, 04:52 PM
Hello,
I have 22 ComboBoxes where the user can choose different values for each one.
The problem I'm having is that I don't know how to iterate through every single comboBox to see if there is a valid selection (a valid selection is anything but '-').
I tried
How do I make it, so it iterates through all 22 comboBoxes and stores the currentText() so I can use it to retrieve info (Main_Category, Sell_Price_$) from another Table within my SQLite Database.
Snippet:
I have 22 ComboBoxes where the user can choose different values for each one.
The problem I'm having is that I don't know how to iterate through every single comboBox to see if there is a valid selection (a valid selection is anything but '-').
I tried
if isinstance
but it only reads the last comboBox and not the rest. How do I make it, so it iterates through all 22 comboBoxes and stores the currentText() so I can use it to retrieve info (Main_Category, Sell_Price_$) from another Table within my SQLite Database.
Snippet:
#---------------------------------------------------------------------------------------------------- # Button Actions #---------------------------------------------------------------------------------------------------- #------------------------------------------ #Submit Button #------------------------------------------ #When the Submit button is clicked -> SubmitClicked Function SubmitButton = self.SubmitButton SubmitButton.clicked.connect(self.SubmitClicked) #------------------------------------------ #---------------------------------------------------------------------------------------------------- # Calculations #---------------------------------------------------------------------------------------------------- #------------------------------------------ # Subtract Material Used from Inventory #------------------------------------------ #TODO: #Grab Main_Category where Name = Material_1-22_ComboBox.currentText() #If Main_Category is Wire: subtract MaterialQuantity from the Total_Length_Ft Column & #populate the MaterialPrice SpinBox with the Price_Per_Ft #Else, subtract the MaterialQuanity from the inventory Quantity & #populate the MaterialPrice SpinBox with the Sell_Price_$ #Apply quantity changes once Submit Button is clicked #Make Database table in Inventory.db so it's easier to work with #------------------------------------------ def SubmitClicked(self): for widget in self.MaterialUsedFrame.children(): if isinstance(widget, QComboBox): SelectedItemName = widget.currentText() #Connect to the inventory database (inventory.db) connection = sqlite3.connect(InventoryDatabase) cursor = connection.cursor() cursor.execute("SELECT Main_Category FROM items WHERE Name = ?",(SelectedItemName,)) connection.commit() Result = cursor.fetchone() #Close the connection connection.close() print(Result) if Result == ('Wire',): #Connect to the inventory database (inventory.db) connection = sqlite3.connect(InventoryDatabase) cursor = connection.cursor() cursor.execute("SELECT Total_Length_Ft, Price_Per_Ft FROM items WHERE Name = ?",(SelectedItemName,)) connection.commit() Result = cursor.fetchone() #Close the connection connection.close() print(Result) else: #Connect to the inventory database (inventory.db) connection = sqlite3.connect(InventoryDatabase) cursor = connection.cursor() cursor.execute("SELECT Quantity, Sell_Price_$ FROM items WHERE Name = ?",(SelectedItemName,)) connection.commit() Result = cursor.fetchone() #Close the connection connection.close() print(Result) #----------------------------------------------------------------------------------------------------Thanks in advance.