Jul-10-2021, 11:04 AM
(This post was last modified: Jul-10-2021, 11:58 AM by Yoriz.
Edit Reason: Added code tags
)
I want to fetch database row values and display it in some labels based upon the selected value of combo box.
The combo box successfully display 'item_name' from table_1 in the combo box. Now, I want to display 'item_name' relevant row values (like item_price, item_code, item_qty etc) in label_1, label_2, label_3 etc., whenever the combo box value changes.
I fetch database and display in the combo box with the following code:
If combobox value 'mango' is selected:
label_1 = MGO
label_2 = 20
label_3 =150
and If combobox value 'apple' is selected:
label_1 = APPL
label_2 = 15
label_3 =180
Thanks in advance.
The combo box successfully display 'item_name' from table_1 in the combo box. Now, I want to display 'item_name' relevant row values (like item_price, item_code, item_qty etc) in label_1, label_2, label_3 etc., whenever the combo box value changes.
I fetch database and display in the combo box with the following code:
def populate_combobox(self): conn = sqlite3.connect('DB.db') c = conn.cursor() c.execute("SELECT item_name FROM table_1") data = c.fetchall() self.comboBox_3.clear() for item_name in data: self.comboBox_3.addItem(item_name[0])Examples: table_1
Output:| id | item_name|item_code|item_qty |item_price|
| -- |----------|---------|---------|----------|
| 1 | mango |MGO | 20 | 150 |
| 2 | banana |BNNA | 5 | 120 |
| 3 | apple |APPL | 15 | 180 |
| 4 | grape |GRPE | 55 | 750 |
| 5 | coconut |CCN | 75 | 820 |
| 6 | pumpkin |PPK | 100 | 980 |
My expectation:If combobox value 'mango' is selected:
label_1 = MGO
label_2 = 20
label_3 =150
and If combobox value 'apple' is selected:
label_1 = APPL
label_2 = 15
label_3 =180
Thanks in advance.