Oups my posting was too big!!! On Tue, Apr 27, 2010 at 11:04 PM, Marco Rompré <marcodrom...@gmail.com>wrote:
> Why is none of my items button works???? In this, I have two files and in > my second file I imported all the function of the first one > > Here is my codes and my error code for the two files please help me: > Traceback (most recent call last): > > > File "F:\School\University\Session 4\Programmation > SIO\magasingolfvues.py", line 426, in <module> > app = App(racine, "magasinmodele.txt") > File "F:\School\University\Session 4\Programmation > SIO\magasingolfvues.py", line 23, in __init__ > ItemsFrame(contexte, item) > NameError: global name 'item' is not defined > >>> > > > 1st fil called magasingolfmodele.py: > > # -*- coding: utf-8 -*- > # > # magasingolfmodele.py > # > # Magasin de golf --< Items de golf > # Magasin de golf (nom, items, ville) > # Items de golf(nom, prix) > # > # naming standards: http://www.python.org/dev/peps/pep-0008/ > # > > > class Magasin: > """ > Le concept magasin pour la gestion d'inventaire des items de golf. > """ > def __init__(self, nom ="", items =[], ville="" ): > self.nom = nom > self.items = items > self.ville = ville > > def set_nom(self, nom): > self.nom = nom > > nom = property(None, set_nom) > > def set_items(self, items): > self.items = items > > items = property(None, set_items) > > def set_ville(self, ville): > self.ville = ville > > ville = property(None, set_ville) > > def __str__(self): > return self.nom > > class Item: > """ > Le concept item pour la gestion d'inventaire des items de golf. > """ > def __init__(self, nom ="", prix = 100): > self.nom = nom > self.prix = prix > > > def set_nom(self, nom): > self.nom = nom > > nom = property(None, set_nom) > > def set_prix(self, prix): > self.prix = prix > > prix = property(None, set_prix) > > def __str__(self): > return self.nom > > > > def initialiser(self): > > > item01 = Item ("Ensemble de fers Titleist") > item01.set_prix("1099.99") > > item02 = Item ("Ensemble de fers Callaway") > item02.set_prix("1299.99") > > item03 = Item ("Ensemble de fers Taylormade Burner Graphite") > item03.set_prix("2499.99") > > item04 = Item ("Ensemble de fers Cobra") > item04.set_prix("999.99") > > item05 = Item ("Ensemble de fers Ping") > item05.set_prix("1399.99") > > item06 = Item ("Ensemble de fers Ben Hogan") > item06.set_prix("1199.99") > > items = [item01, item02, item03, item04, item05, item06] > magasin01.set_items(items) > > items = [item01, item03, item04, item06] > magasin02.set_items(items) > > items = [item01, item02, item03, item05] > magasin03.set_items(items) > > magasins = [magasin01, > magasin02, > magasin03] > > self.set_magasins(magasins) > > self.sauvegarder() > > def afficher(self): > print("") > print("Magasins") > for magasin in self.magasins: > print("") > print(magasin) > print("") > for item in magasin.items: > print(item) > for prix in item.prix: > print(prix) > > > if __name__ == '__main__': > modele = Modele("magasinmodele.txt") > modele.charger() > if modele.vide(): > modele.initialiser() > modele.afficher() > > > Here's the code of my second file: > > # -*- coding: utf-8 -*- > # > # magasingolfvues.py > # > # naming standards: http://www.python.org/dev/peps/pep-0008/ > # > > from Tkinter import * > > from magasingolfmodele import * > > class App: > """ > Application illustrant le concept d'un magasin de golf et des items > qu'il vend. > """ > def __init__(self, contexte, nom_fichier): > self.contexte = contexte > self.modele = Modele(nom_fichier) > self.modele.charger() > if self.modele.vide(): > self.modele.initialiser() > MagasinsFrame(self) > ItemsFrame(contexte, item) > > > class ItemsFrame(Toplevel): > """ > Liste des items. > """ > def __init__(self, contexte, items): > Toplevel.__init__(self, contexte) > self.contexte = contexte > self.items = items > > self.title("Gestion des items de golf") > titre = Label(self, text = "Bâtons de golf disponibles (nom)") > titre.pack() > > self.liste = Listbox(self) > for items in self.items: > self.liste.insert(END, items) > self.liste.pack() > > self.afficher_item_bouton = Button( > self, text = "Item", fg = "blue", command = self.afficher_item > ) > self.afficher_item_bouton.pack(side = LEFT) > > self.ajouter_item_bouton = Button( > self, text = "Ajouter", fg = "blue", command = > self.ajouter_item > ) > self.ajouter_item_bouton.pack(side=LEFT) > > self.afficher_item_bouton = Button( > self, text = "Modifier", fg = "blue", command = > self.modifier_item > ) > self.afficher_item_bouton.pack(side = LEFT) > > self.supprimer_facture_bouton = Button( > self, text = "Supprimer", fg = "red", command = > self.supprimer_item > ) > self.supprimer_facture_bouton.pack(side=LEFT) > > self.afficher_nom_bouton = Button( > self, text = "Nom", fg = "blue", command = self.afficher_nom > ) > self.afficher_nom_bouton.pack(side = LEFT) > > self.afficher_prix_bouton = Button( > self, text = "Prix", fg = "blue", command = self.afficher_prix > ) > self.afficher_prix_bouton.pack(side = LEFT) > > sortir_bouton = Button( > self, text = "Sortir", fg = "red", command = self.quit > ) > sortir_bouton.pack(side = LEFT) > > > def afficher_item(self): > items = self.liste.curselection() > items = [self.app.modele.items[int(item)] for item in items] > if (items != []): > items = items[0] > itemsFrame = ItemsFrame(self, item) > > def ajouter_item(self): > itemAjouterFrame = ItemAjouterFrame(self, self.app.modele.items) > > def modifier_item(self): > items = self.liste.curselection() > items = [self.app.modele.items[int(item)] for item in items] > if (items != []): > item = items[0] > ItemModifierFrame(self, items) > > def supprimer_item(self): > items = self.liste.curselection() > items = [self.app.modele.items[int(item)] for item in items] > if (items != []): > items = items[0] > self.app.modele.items.remove(items) > self.app.modele.sauvegarder() > item = items[0] > self.liste_supprimer(item) > > def afficher_nom(self): > items = self.liste.curselection() > items = [self.app.modele.items[int(item)] for item in items] > if (items != []): > items = magasins[0] > itemsFrame = ItemsFrame(self, magasin.items.nom) > > def afficher_prix(self): > items = self.liste.curselection() > items = [self.app.modele.items[int(item)] for item in items] > if (items != []): > items = magasins[0] > itemsFrame = ItemsFrame(self, magasin.items.prix) > > def liste_ajouter(self, items): > self.liste.insert(END, items) > > def liste_modifier(self, item, items): > self.liste.delete(item) > self.liste.insert(item, items) > > def liste_supprimer(self, item): > self.liste.delete(item) > > class ItemFrame(Toplevel): > """ > Un certain item de golf. > """ > def __init__(self, contexte, item): > Toplevel.__init__(self, contexte) > > self.title("Item") > > nom_etiquette = Label(self, text = "Nom l'item : " + item.nom, bg = > "white", fg= "red") > nom_etiquette.pack() > > nom_etiquette = Label(self, text = "Nom de la ville : " + > items.prix, bg = "white", fg= "blue") > nom_etiquette.pack() > > sortir_bouton = Button( > self, text = "Sortir", fg = "red", command = self.quit > ) > sortir_bouton.pack(side = LEFT) > > class ItemAjouterFrame(Toplevel): > """ > Ajouter un item. > """ > def __init__(self, contexte, magasins): > Toplevel.__init__(self, contexte) > self.contexte = contexte > self.items = items > > > self.title("Ajouter") > titre = Label(self, text = "Item") > titre.pack() > > nom_etiquette = Label(self, text = "Nom", bg = "white") > nom_etiquette.pack() > self.nom_entree = Entry(self) > self.nom_entree.pack() > > self.ajouter_item_bouton = Button( > self, text = "Ajouter", command = self.ajouter_item > ) > self.ajouter_item_bouton.pack(side=LEFT) > > sortir_bouton = Button( > self, text = "Sortir", fg = "blue", command = self.quit > ) > sortir_bouton.pack(side=LEFT) > > def ajouter_item(self): > nom = self.nom_entree.get() > if nom.strip() == "": > nom = "?" > item = Item(nom) > self.item.append(item) > self.contexte.app.modele.sauvegarder() > self.contexte.liste_ajouter(items) > > class ItemModifierFrame(Toplevel): > """ > Modifier un item dans la liste d'items. > """ > def __init__(self, contexte, magasin): > Toplevel.__init__(self, contexte) > self.contexte = contexte > self.items = items > > self.title("Modifer") > titre = Label(self, text = "Item de golf") > titre.pack() > > nom_etiquette = Label(self, text = "nom", bg = "white") > nom_etiquette.pack() > self.nom_entree = Entry(self) > self.nom_entree.insert(0, self.magasin.items.nom) > self.nom_entree.pack() > nom_etiquette = Label(self, text = "prix", bg = "white") > nom_etiquette.pack() > self.nom_entree = Entry(self) > self.nom_entree.insert(0, self.magasin.items.prix) > self.nom_entree.pack() > > self.modifier_item_bouton = Button( > self, text = "Modifier", command = self.modifier_magasin > ) > self.modifier_item_bouton.pack(side=LEFT) > > sortir_bouton = Button( > self, text = "Sortir", fg = "blue", command = self.quit > ) > sortir_bouton.pack(side = LEFT) > > def modifier_item(self): > nom = self.nom_entree.get() > if nom.strip() == "": > nom = "?" > self.nom_entree.insert(0, nom) > self.item.set_nom(nom) > self.contexte.app.modele.sauvegarder() > items = self.contexte.liste.curselection() > item = items[0] > self.contexte.liste_modifier(item, self.items) > > > if __name__ == '__main__': > racine = Tk() > app = App(racine, "magasinmodele.txt") > racine.mainloop() > racine.destroy() > > Thank You for your help!!! > > > > -- > Marc-O. Rompré > > -- Marc-O. Rompré
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor