IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Tkinter Python Discussion :

erreur à la compilation


Sujet :

Tkinter Python

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Futur Membre du Club
    Profil pro
    Inscrit en
    Avril 2010
    Messages
    3
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2010
    Messages : 3
    Par défaut erreur à la compilation
    Bonjour,

    lorsque je compile mon programme de tracé de trochoides, j'obtiens cette erreur:
    File "C:\Users\Chris\Desktop\spiro2.py", line 95, in fonction
    color = cb_color()
    NameError: global name 'cb_color' is not defined

    et je ne comprends pas du tout pourquoi cb_color n'est pas (ou mal) défini.
    c'est surement une erreur assez bête mais je n'arrive pas à la trouver, si vous pouviez m'aider ce serait très sympa.
    Merci d'avance

    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
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
       1. # ==============================================================================
       2. # Tracé de Trochoïdes
       3. # ==============================================================================
       4. """Tracé de trochoïdes"""
       5. __author__  = "Gaëlle Conte"
       6. __version__ = "1.0"
       7. __date__    = "mai 2010"
       8. # ------------------------------------------------------------------------------
       9. from Tkinter import *
      10. from tkFont import Font
      11. import math
      12. import tkColorChooser
      13. #-------------------------------------------------------------------------------
      14. class debut():
      15.   """crée l'affichage du jeu"""
      16.
      17.   def __init__(self):
      18.     self.root
      19.  
      20.   global root
      21.   root = {0: Tk()}
      22.   # ----------------------------------------------------------------------------
      23.   root[1] = Frame(root[0])
      24.   root[1].pack(side=TOP, fill=BOTH)
      25.   root[11] = Frame(root[1])
      26.   root[11].pack(side=LEFT, fill=BOTH)
      27.   root[12] = Canvas(root[1], bg='white',width=500, height=500, relief=SOLID, border=3)
      28.   root[12].pack(side=LEFT, fill=BOTH, expand=YES)
      29.
      30. # ------------------------------------------------------------------------------
      31. class choix_util(): 
      32.
      33.   def __init__(self,x,y):
      34.     self.x = x
      35.     self.y = y
      36.
      37.
      38.   root[111]= Frame(root[11])
      39.   root[111].pack(side=TOP, fill=BOTH,pady=5)
      40.
      41.   root[1111]=Frame(root[111])
      42.   root[1111].pack(side=LEFT,fill=BOTH,pady=5)
      43.   root[11111]=Label(root[1111],text='position de x')
      44.   root[11111].pack(side=TOP, fill=BOTH,pady=5)
      45.   root[11112] = Scale(root[1111], orient=HORIZONTAL, to=400)
      46.   root[11112].pack(side=TOP, fill=BOTH, expand=YES)
      47.
      48.   root[1112]=Frame(root[111])
      49.   root[1112].pack(side=LEFT,fill=BOTH,pady=5)
      50.   root[11121]=Label(root[1112],text='position de y')
      51.   root[11121].pack(side=TOP, fill=BOTH,pady=5)
      52.   root[11122] = Scale(root[1112], orient=HORIZONTAL, to=400)
      53.   root[11122].pack(side=TOP, fill=BOTH, expand=YES)
      54.   # ----------------------------------------------------------------------------
      55.   root[112] = Label(root[11], text='rayon de cercle fixe (1-100)')
      56.   root[112].pack(side=TOP, fill=BOTH,pady=5)
      57.   root[113] = Scale(root[11], orient=HORIZONTAL,from_=1, to=100)
      58.   root[113].pack(side=TOP, fill=BOTH, expand=YES)
      59.   root[114] = Label(root[11], text='deplacement du rayon du cercle (1-100)')
      60.   root[114].pack(side=TOP, fill=BOTH)
      61.   root[115] = Scale(root[11], orient=HORIZONTAL, from_=1, to=100)
      62.   root[115].pack(side=TOP, fill=BOTH, expand=YES)
      63.   root[116] = Label(root[11], text='deplacement de compensation du cercle (1-100)')
      64.   root[116].pack(side=TOP, fill=BOTH)
      65.   root[117] = Scale(root[11], orient=HORIZONTAL, from_=1, to=100)
      66.   root[117].pack(side=TOP, fill=BOTH, expand=YES)
      67.
      68.   x = root[11112].get()
      69.   y = root[11122].get()
      70. # ------------------------------------------------------------------------------
      71. class spiro():
      72.   """Zone de dessin"""
      73.
      74.   global color
      75.  
      76.   # ----------------------------------------------------------------------------
      77.   def __init__(self,x,y):
      78.     self.pos_x = choix_util(x)
      79.     self.pos_y = choix_util(y)
      80.
      81.   # ------------------------------------------------------------------------------
      82.   def cb_color(self, val=None):
      83.     """permet à l'utilisateur de choisir la couleur de la courbe"""
      84.     val=tkColorChooser.askcolor()
      85.     return val
      86.  
      87.   # ----------------------------------------------------------------------------
      88.   def fonction(self, pos=None):
      89.     """ """
      90.
      91.     #a = spiro(x)
      92.     #b = spiro(y)
      93.     x = root[11112].get()
      94.     y = root[11122].get()
      95.     color = cb_color()
      96.  
      97.     R, r, O = root[113].get(), root[115].get(), root[117].get()
      98.
      99.     if pos is None:
     100.       coords=[]
     101.       for t in range(500):
     102.         coords.append((R+r)*math.cos(t)-O*math.cos(((R+r)/r)*t)+x)
     103.         coords.append((R+r)*math.sin(t)-O*math.sin(((R+r)/r)*t)+y)
     104.       outside_curve=root[11].create_line(coords,fill=color,tag='line',activedash=(2,2))
     105.      
     106.     else:
     107.       coords=[]
     108.       for t in range(500):
     109.         coords.append((R-r)*math.cos(t)+O*math.cos(((R-r)/r)*t)+self.pos_x)
     110.         coords.append((R-r)*math.sin(t)-O*math.sin(((R-r)/r)*t)+self.pos_y)
     111.       inside_curve=root[11].create_line(coords,fill=color,tag='line',activedash=(2,2))
     112.      
     113.
     114.   # ------------------------------------------------------------------------------
     115.   def cb_delete():
     116.     """supprime tous les dessins dans la fenetre"""
     117.     root[11].delete(root[11],'line')
     118.
     119.
     120.   root[118] = Frame(root[11])
     121.   root[118].pack(side=TOP,fill=BOTH,expand=YES)
     122.   root[1181] = Button(root[118], text='déplacement intérieur',command = fonction(True))
     123.   root[1181].pack(side=LEFT, fill=BOTH, expand=YES,pady=5,padx=5)
     124.   root[1182] = Button(root[118], text='déplacement extérieur',command = fonction(False))
     125.   root[1182].pack(side=LEFT, fill=BOTH, expand=YES,pady=5,padx=5)
     126.   root[119] = Button(root[11], text= 'effacer', command=cb_delete)
     127.   root[119].pack(side=TOP, fill=BOTH,padx=5,pady=2)
     128.      
     129. # ==============================================================================
     130. if __name__ == '__main__': # testcode de la classe spiro
     131.   # ----------------------------------------------------------------------------
     132.   root=debut()
     133.   root.title('Trace de Trochoides')
     134.   root.protocol('WM_DELETE_WINDOW', root.quit)
     135.   root.minsize(root.winfo_width(), root.winfo_height())
     136.   root.resizable(1,1)
     137.   root.mainloop(); root.destroy()
     138. # ==============================================================================

  2. #2
    Expert éminent
    Homme Profil pro
    Architecte technique retraité
    Inscrit en
    Juin 2008
    Messages
    21 687
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Manche (Basse Normandie)

    Informations professionnelles :
    Activité : Architecte technique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2008
    Messages : 21 687
    Par défaut
    Salut,
    cb_color n'est pas une fonction dans l'espace "global" mais une méthode de spiro. Pour que l'interpreteur la trouve, il suffit d'ajouter "self." devant:
    color = self.cb_color()
    - W
    Architectures post-modernes.
    Python sur DVP c'est aussi des FAQs, des cours et tutoriels

Discussions similaires

  1. Erreur de compilation après modification du Uses
    Par DevelOpeR13 dans le forum Langage
    Réponses: 5
    Dernier message: 30/10/2007, 14h23
  2. Réponses: 2
    Dernier message: 23/09/2003, 14h32
  3. Réponses: 10
    Dernier message: 22/09/2003, 21h58
  4. Réponses: 4
    Dernier message: 27/08/2003, 21h34
  5. Réponses: 2
    Dernier message: 04/03/2003, 23h24

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo