i use python 3, tkinter and mysql connector. I want to make an optionMenu object with my sql data i tried to do like that :
mongroupe3 = LabelFrame(app, text='nouvelle div 3').pack()
Label(mongroupe3, text='groupe3').pack()
select_Classes = ("select id,nom from classe")
cursor.execute(select_Classes)
result = cursor.fetchall()
for row in result:
id = row[0]
nom = row[1]
mongroupe3 = Label(app, text=nom).pack()
v = StringVar()
v.set(nom)
om = OptionMenu(mongroupe3, v, nom)
om.pack()
the code has to show a dropdown menu with a list of the "nom" on my "classe" table but my option menu is in my for loop and is executed as many time as i have records in my classe table .
for exemple if i have 3 record i got 3 option menu with 3 different value.
o tried to put my optionMenu out of my for loop like that :
mongroupe3 = LabelFrame(app, text='nouvelle div 3').pack()
Label(mongroupe3, text='groupe3').pack()
select_Classes = ("select id,nom from classe")
cursor.execute(select_Classes)
result = cursor.fetchall()
for row in result:
id = row[0]
nom = row[1]
mongroupe3 = Label(app, text=nom).pack()
v = StringVar()
v.set(nom)
om = OptionMenu(mongroupe3, v, nom)
om.pack()
but i got only the last record i inserted on my table.
i cant put my for loop inside my OptionMenu cause of the following shema OptionMenu(parent, default variable, var)