我们可以将Entry更改为对象吗?

嗨,大家好, 因此,我坚持5个小时来解决一个小问题,我真的不知道该如何解决。所以我做了两个类,一个叫“ Categorie”,另一个叫“ Aliments”,所以我实际上是在使用Tkinter,看起来很简单,这是一个大问题。我创建了一个条目,假定该条目接收对象的信息,并且更改的属性名为“代码”。因此,我决定创建一个函数,该函数将获取此信息并将其传输到名为“ modifierCode”的函数中 该函数从前2个条目中获取信息,并假设使用对象名称并通过条目中的内容更改“ code”属性。问题是我得到一个错误,谁说alimentNom(对象的名称)是一个str没有任何属性代码。我认为我的主要问题是这是一个字符串,但我真的不知道如何解决此问题。我真的需要帮助,我已经与很多专家进行了交谈,他们甚至都不知道该如何解决!希望我已经足够清楚了:)。

from tkinter import *

class Catégorie (object):
    def __init__(self,nom,liste=[]):
        self._categorie = nom
        self._liste = []
        liste.append(self._categorie)

    def _get_categorie(self):
        return self._categorie

    def _set_categorie(self,nom):
        self._categorie = nom

    nom = property(_get_categorie,_set_categorie)


class Aliment (Catégorie):
    def __init__(self,nom,code,prix):
        self._nom = nom
        self._code = code
        self._prix = prix
    def _get_code(self):
        return self._code
    def _set_code(self,code):
        self._code = code;
        texteModification = Label(text=("l'aliment {} a un nouveau code {}.".format(self._nom, self._code)))
        print(texteModification)

    code = property(_get_code,_set_code)

def AjoutCat():
    nom = var_texte.get()
    nom = Catégorie(nom)
    message1 = Label(window,text=("La catégorie {} à été ajouté".format(nom._categorie)),fg="Green")
    message1.pack()

def AjoutAliment():
    codeAli = codeEntree.get()
    prixAli = prix.get()
    nomAliment = aliment.get()
    categorieAli = categorie.get() #Nom de la Catégorie choisis

    alimentEntree = Aliment(nomAliment,codeAli,prixAli)
    alimentEntree._categorie = categorieAli
    message2 = Label(window, text=("Catégorie de l'aliment: {}, Nom de l'aliment: {}, Code de l'aliment: {}, Prix de l'aliment : {}$ ".format(alimentEntree._categorie, alimentEntree._nom, alimentEntree._code, alimentEntree._prix)), fg="Green")
    message2.pack()

def modifierCode ():
    alimentCode = nouveauCode.get()
    alimentNom = ajoutNom.get()
    alimentNom = object
    alimentNom.code  = alimentCode

window = Tk()
window.title("Aliments du Supermarché")
window.geometry("600x900") #Dimension de la fenêtre

#Texte
titre1 = Label(window,text="Ajouter un catégorie",fg="Blue")
titre1.pack()

#Nom de la catégorie

var_texte = StringVar()
entree1 = Entry(window, textvariable=var_texte, width="50")
entree1.pack()

#Bouton qui rajoute la catégorie

bouton1 = Button(window,text="Ajouter",command=AjoutCat)
bouton1.pack()

#Entrée pour les informations sur l'aliment

titre2 = Label(window,text="Ajouter un aliment:",fg="Blue")  #Titre
titre2.pack()
texte1 = Label(window,text="Catégorie de l'aliment:",fg="Black")  #Sous-Titre
texte1.pack()
categorie = StringVar()
entree2 = Entry(window, textvariable=categorie, width="30")
entree2.pack()

texte2 = Label(window,text="Nom de l'aliment:",fg="Black") #Sous-Titre
texte2.pack()
aliment = StringVar()
entree3 = Entry(window, textvariable=aliment, width="30")
entree3.pack()

texte3 = Label(window,text="Code de l'aliment:",fg="Black")  #Sous-Titre
texte3.pack()
codeEntree = IntVar()
entree4 = Entry(window,textvariable=codeEntree, width="30")
entree4.pack()

texte4 = Label(window,text="Prix de l'aliment:",fg="Black")  #Sous-Titre
texte4.pack()
prix = IntVar()
entree5 = Entry(window, textvariable=prix, width="10")
entree5.pack()

#Bouton pour ajouter les aliments
bouton2 = Button(window,text="Ajouter", command=AjoutAliment) #Bouton Ajouter
bouton2.pack()

#Modifier
titre3 = Label(window,text="Modifier le code de l'aliment :",fg="Red") #Titre
titre3.pack()

texte5 = Label(window,text="Nom de l'aliment :",fg="Black") #Sous-Titre
texte5.pack()
ajoutNom = StringVar()
entree6 = Entry(window, textvariable=ajoutNom, width="10")
entree6.pack()

texte6 = Label(window,text="Nouveau Code :",fg="Black") #Sous-Titre
texte6.pack()

nouveauCode = IntVar()
entree7 = Entry(window, textvariable=nouveauCode, width="30") #Entrée
entree7.pack()

bouton3 = Button(window,text="Modifier",command=modifierCode) #Bouton Ajouter
bouton3.pack()

#Supprimer une catégorie

titre4 = Label(window,text="Modifier le code de l'aliment :",fg="Red") #Titre
titre4.pack()

texte7 = Label(window,text="Catégorie :",fg="Black") #Sous-Titre
texte7.pack()

suprimmerCat = StringVar()
entree7 = Entry(window, textvariable=suprimmerCat, width="30") #Entrée
entree7.pack()

bouton4 = Button(window,text="Supprimer", command=AjoutAliment) #Bouton Ajouter
bouton4.pack()


#Affichage

window.mainloop()