'update my mysql database, update also combobox list tkinter python
What this code do is that to get all the values in a certain column from the mysql database and then use those values as list values of combobox in tkinter python.
but this code doesn't update whenever I made changes in my database mysql. The list in combobox doesn't change/ update whenever I add or delete something in my database mysql.
what is the best solution to this?
dat_list2=list()
var_cbx = tk.StringVar()
la_bel_cbx = tk.Label(self, textvariable=var_cbx, fg='red', bg='gray')
la_bel_cbx.place(x=4, y=400)
def cbx_data():
nonlocal dat_list2
mydb1 = pymysql.connect(host='localhost',
user='root',
password='',
database='user_name_password')
mydb = mysql.connector.connect(host='localhost',
user='root',
password='',
database='user_name_password')
conn3 = mydb1.cursor()
conn3.execute('SELECT un FROM user_data')
lst_names=conn3.fetchall()
for un in lst_names:
dat_list2.append(un)
var_cbx.set(str(dat_list2))
self.after(10,cbx_data)
cbx_data()
dat_list = ['a', 'b', 'c']
cb1 = ttk.Combobox(self, values=dat_list2)
cb1.place(x=35,y=170)
THANK YOU IN ADVANCE
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
