Python Forum
How to fetch database row values and display it in some labels
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to fetch database row values and display it in some labels
#1
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:

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.
Yoriz write Jul-10-2021, 11:58 AM:
Please post all code, output and errors (in their entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020