Bonjour,

je suis en train de créer une interface graphique avec Tkinter qui reprends des données de ma bdd mysql.

Mon premier problème est dans ma manière de récupérer mes données (lignes 29-31) et de les insérer dans une combobox (ça me renvois les valeurs comme ça :
[('Aliments
et
boissons
à
base
de
végétaux',),
("Aliments
d'origine
végétale",), ........

au lieu de :

Aliments et boissons à base de végétaux
Aliments d'origine végétale
....


Et je cherche en ce moment le moyen d'afficher les produits sous ma combobox, de la catégorie sélectionnée dans ma combobox mais je ne trouve pas de widget pour ça (a part listbox (ligne 33-37), mais je ne suis pas sur que ça soit adapté) donc si vous pouvez m'aiguiller ça m'aiderait sinon je continu a chercher quand même.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
 
from tkinter import *
import tkinter as tk
from tkinter import tix, ttk
import mysql.connector
 
 
#creation window
window = tk.Tk()
 
#format window
window.title("Database OpenFoodFact") 
window.geometry("950x400")
 
lst = ["1", "2"]
 
def __inti__(self):
	second_window()
 
def second_window():
	second_window = tk.Toplevel(window, bg = "#FAFAFA")
	second_window.geometry("920x400")
	labelCategory = tk.Label(second_window, text = "Catégories : ", bg = "#FAFAFA").grid(row=0, column=1)
	MYSQL_USER = '***'
	MYSQL_HOST = '***'
	MYSQL_PWD = '***'
	MYSQL_DATABASE = '****'
	connexion_data_base = mysql.connector.connect(user=MYSQL_USER, password=MYSQL_PWD, host=MYSQL_HOST, database=MYSQL_DATABASE)
	cursor = connexion_data_base.cursor()
	cursor.execute(" SELECT category FROM Category")
	data = str(cursor.fetchall())
	comboExample = ttk.Combobox(second_window, values=data, width=30).grid(row=1, column=1, padx=50, pady=10)
	cursor.execute(" SELECT food FROM Food")
	food = str(cursor.fetchall())
	listbox = Listbox(second_window).grid(row=2, column=2)
	for i in range(11):
		listbox.insert(food)
	cursor.close()
	#labelDescription = tk.Label(second_window, text = "Description")
	second_window.mainloop()
 
 
#creation title
label_title = Label(window, text="Bienvenue dans la base de donnée OpenFoodFacts", font=("Helvetica", 40), fg="#41B77F").pack()
 
#creation image
width = 300
height = 300
image = PhotoImage(file="/Users/macbookair/Documents/Projet_5/PureBeurre/openfoodfacts-logo-fr-178x150.png")
canvas = Canvas(window, width=width, height=height)
canvas.create_image(width/2, height/2, image=image)
canvas.pack()
 
#creation button
button_connect = tk.Button(window, text="Trouver un aliment à remplacer", command=second_window).pack(side=LEFT, padx = 100)
button_connect2 = tk.Button(window, text="Retrouver mes aliments substitués").pack(side=RIGHT, padx = 100)
 
# print window
window.mainloop()