Partage
  • Partager sur Facebook
  • Partager sur Twitter

[Python] Une classe qui ne marche pas

Sujet résolu
    18 mai 2007 à 10:25:21

    Bonjour :)


    Je suis en train de me programmer une calculatrice, et je compte y ajouter des fonctions. Je me suis donc dit que ça serait bien d'ajouter un menu, comme dans le livre de Swinnen, j'ai donc recopié son code, j'ai essayé et... mon programme plante...
    voici l'erreur affichée :
    Traceback (most recent call last):
      File "/Users/loic/cat_loic/python/catculapy.py/catculapy.py", line 70, in <module>
        app = Application()
      File "/Users/loic/cat_loic/python/catculapy.py/catculapy.py", line 45, in __init__
        self.mBar = MenuBarre()
    NameError: global name 'MenuBarre' is not defined

    En gros, il ne comprend pas que MenuBarre est une classe...
    Voici mon code :
    # -*- coding: utf-8 -*-

    #nom : catculapy.py, calculatrice en Python ( mode fênetre ) version 1.0.0
    #Copyright (C) 2007  Loïc Chardonnet

    #This program is free software; you can redistribute it and/or modify
    #it under the terms of the GNU General Public License as published by
    #the Free Software Foundation; either version 2 of the License, or
    #(at your option) any later version.

    #This program is distributed in the hope that it will be useful,
    #but WITHOUT ANY WARRANTY; without even the implied warranty of
    #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    #GNU General Public License for more details.

    #You should have received a copy of the GNU General Public License
    #along with this program; see the file COPYING. If not, write to the
    #Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

    from Tkinter import *
    from math import *

    # Modules
    class MenuBare(Frame):
        "Barre de menu déroulant"
        def __init__(self, boss=None):
            "Fonction d'initialisation"
            Frame.__init__(self, borderwidth=2)

            # 1 ) Menu "catculapy"
            fileMenu = Menubutton(self, text='catculapy')
            fileMenu.pack(side=LEFT)
            # 1.1 ) Partie déroulante :
            me1.add_command(label='Quitter', underline=0, command=boss.quit)
            # 1.2 ) Intégration du menu :
            fileMenu.configure(menu =me1)

    class Application():
        "Application principale"
        def __init__(self, boss=None):
            "Fonction d'initialisation"
            self.root = Tk()
            self.root.geometry('250x50')
            self.root.title('catculapy, la calculatrice !')
            self.mBar = MenuBarre()
            self.mBar.pack()
            self.can = Canvas(self.root, borderwidth=2)
            self.can.pack()
            self.chaine = Label(self.can)
            self.chaine.pack(side=BOTTOM)
            self.entree = Entry(self.can)
            self.entree.bind("<Return>", self.calculer)
            self.entree.pack()
            self.root.mainloop()

        def calculer(self, event):
            "Fonction qui calcule ce que l'utilisateur à entré"
            global test, resultat
            test = self.entree.get()
            if test == "":     
                resultat = 0

            else:
                resultat = str(eval(self.entree.get()))

            self.chaine.configure(text="Résultat = " + str(resultat))

    # Programme principal
    if __name__ == '__main__':
        app = Application()


    Merci d'avance pour votre aide :)
    • Partager sur Facebook
    • Partager sur Twitter
      18 mai 2007 à 10:54:05

      NameError: global name 'MenuBarre' is not defined

      class MenuBare

      c'est juste une faute de frappe :)
      • Partager sur Facebook
      • Partager sur Twitter
        18 mai 2007 à 10:56:30

        Oups O.o
        c'est vrai, j'avais pas vu !
        Merci beuacoup :)
        ( comme quoi, un regard extérieur est toujours nécessaire ! )
        • Partager sur Facebook
        • Partager sur Twitter

        [Python] Une classe qui ne marche pas

        × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
        × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
        • Editeur
        • Markdown