Bonjour,

je cherche désespérément la solution a mon problème, je ne comprends pas ou est l'erreur


code erreur : File "interface.py", line 277, in get_select_category. LA LIGNE 277 = ligne 22 du deuxième code
select.select_food(get_index.get_category_food())
AttributeError: 'str' object has no attribute 'get_category_food'

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
 
import mysql.connector
from Constant import *
 
 
 
class mysql_select:
 
 
	def select_category(self):
		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")
		self.data_category = cursor.fetchall()
		self.data_category = [d[0] for d in self.data_category] 
		return self.data_category
 
	def select_food(self, idCategory):
		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 food FROM Food WHERE idCategory ="+idCategory)
		self.data_food = cursor.fetchall()
		self.data_food = [d[0] for d in self.data_food]
		return self.data_food
 
	def select_substitute(self, idCategory):
		cursor.execute("SELECT substitute FROM Substitute WHERE idCategory="+idCategory)
		self.data_susbstitute = cursor.fetchall()
		self.data_susbstitute = [d[0] for d in self.data_susbstitute]
		return self.data_susbstitute


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
60
61
62
63
64
65
66
67
68
69
 
 
 
from tkinter import Button, Canvas, RIGHT, LEFT, PhotoImage, Label, N, S, E, W
import tkinter as tk
from tkinter import ttk
from tkinter.ttk import Combobox
import mysql.connector
from Constant import *
from SelectMysql import mysql_select
 
select = mysql_select()
 
class tkinterWindow:
#..... j'ai retiré volontairement cette partie de mon code car je ne pense pas que le problème soit la
 
	def get_select_category():
		global comboExample
		get_index = comboExample.current()
		get_index = get_index + 1
		get_index = str(get_index)
		select.select_food(get_index.get_category_food())
		select.select_substitute(get_index.get_category_food())
 
	def get_category_food():
		comboExample1 = ttk.Combobox(second_window, values=select.select_food(), width=30)
		comboExample1.grid(row=2, column=1)
		comboExample2 = ttk.Combobox(second_window, values=select.select_substitute(), width=30)
		comboExample2.grid(row=0, column=6)
 
 
	if __name__ == "__main__":
 
		global comboExample
		# creation window
		window = tk.Tk()
		# format window
		window.title("Database OpenFoodFact")
		window.geometry("950x400")
		# 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/GitHub/PureBeurre/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=window.destroy).pack(side=LEFT, padx=100)
		button_connect2 = tk.Button(window, text="Retrouver mes aliments substitués", command=substitute_food).pack(side=RIGHT, padx=100)
		# print window
		window.mainloop()
		second_window = tk.Tk()
		second_window.configure(bg="#CECECE")
		second_window.geometry("950x650")
 
		labelCategory = tk.Label(second_window, text="Catégories : ", relief="solid", bg="#FEFEFE").grid(row=0, column=0)
		comboExample = ttk.Combobox(second_window, values=select.select_category(), width=30)
		comboExample.grid(row=0, column=1)
		button_choice_category = Button(second_window, text="Valider", command=get_select_category).grid(row=1, column=1)
		button_choice_food = Button(second_window, text="Valider", command=get_ingredients).grid(row=3, column=1)
		button_choice_subsitute = tk.Button(second_window, text="Valider", command=get_substitute).grid(row=1, column=6)
		labelFood = tk.Label(second_window, text="Aliments : ", relief="solid", bg="#FEFEFE").grid(row=2, column=0)
		label_subsitute = tk.Label(second_window, text="Aliments à substituer :", relief="solid", bg="#FEFEFE").grid(row=0, column=5)
		button_subsitute_food = tk.Button(second_window, text="Substituer aliment", command=saved_substitute, bg="#FAFAFA").grid(row=29, column=5, sticky="w")
		button_subsitute = tk.Button(second_window, text="Historique", command=substitute_food, bg="#FAFAFA").grid(row=29, column=6, sticky="e")
		space = tk.Label(second_window, text="            ", bg="#CECECE"). grid(row=0, column=4)
		second_window.mainloop()