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

Python Discussion :

petit probleme de programme


Sujet :

Python

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre à l'essai
    Profil pro
    Inscrit en
    Juillet 2008
    Messages
    4
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2008
    Messages : 4
    Par défaut petit probleme de programme
    Bnjour,
    Je suis actuellement le livre de Gérard Swinnen pour apprendre python et j'ai un petit problème avec un programme que je n'arrive pas a exécuter (où est l'erreur?)

    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
    from Tkinter import*
    from random import randrange
     
    def drawline():
            "Tracé d'une ligne dans le canevas can1"
    	global x1,y1, x2,y2, cou1#FF3434
    	can1.create_line(x1,y1,x2,y2,width=2,fill=cou1)
        #modification des coordonnées pour la ligne suivante :  
            y2,y1 = y2+10 , y1-10
    def changecolor():
    	"changement aléatoire de la couleur du tracé"
    	global cou1
    	pa1=['purple','cyan','maroon','green','red','blue','orange','yellow']
    	c = randrange (8)
    	cou1
     
    #---------------Pgm principal---------
    #les variables suivantes seront utilisées de manière globale :
    x1,y1, x2,y2,=10,190,190,10
    cou1 = 'dark green'
     
    #création du widget principal ("maitre") :
    fen1 = Tk()
    # création du widget "esclave":
    can1 = Canvas (fen1,bg='dark green', height=200, width=200)
    can1.pack(side=LEFT)
    bou1= Button (fen1,text='Quitter',command=fen1.quit)
    bou1.pack(side=BOTTOM)
    bou2 = Button(fen1,text='Tracer une ligne',command-drawline)
    bou2.pack()
    bou3 = Button (fen1,text ='Autre couleur' ,command=changecolor)
    bou3.pack()
    fen1.mainloop()
    fen1.destroy()

  2. #2
    Membre à l'essai
    Profil pro
    Inscrit en
    Juillet 2008
    Messages
    4
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2008
    Messages : 4
    Par défaut
    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
    Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52) 
    [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from Tkinter import*
    >>> from random import randrange
    >>> 
    >>> def drawline():
    ...     "Tracé d'une ligne dans le canevas can1"
    ...     global x1,y1, x2,y2, cou1#FF3434
      File "<stdin>", line 3
        global x1,y1, x2,y2, cou1#FF3434
        ^
    IndentationError: unexpected indent
    >>>     can1.create_line(x1,y1,x2,y2,width=2,fill=cou1)
      File "<stdin>", line 1
        can1.create_line(x1,y1,x2,y2,width=2,fill=cou1)
        ^
    IndentationError: unexpected indent
    >>>     #modification des coordonnées pour la ligne suivante :  
    ... y2,y1 = y2+10 , y1-10
    Traceback (most recent call last):
      File "<stdin>", line 2, in <module>
    NameError: name 'y2' is not defined
    >>> def changecolor():
    ...     "changement aléatoire de la couleur du tracé"
    ...     global cou1
    ...     pa1=['purple','cyan','maroon','green','red','blue','orange','yellow']
    ...     c = randrange (8)
    ...     cou1
    ...     
    ... #---------------Pgm principal---------
    ... #les variables suivantes seront utilisées de manière globale :
    ... x1,y1, x2,y2,=10,190,190,10
      File "<stdin>", line 10
        x1,y1, x2,y2,=10,190,190,10
         ^
    SyntaxError: invalid syntax
    >>> cou1 = 'dark green'
    >>> 
    >>> #création du widget principal ("maitre") :
    ... fen1 = Tk()
    >>> # création du widget "esclave":
    ... can1 = Canvas (fen1,bg='dark green', height=200, width=200)
    >>> can1.pack(side=LEFT)
    >>> bou1= Button (fen1,text='Quitter',command=fen1.quit)
    >>> bou1.pack(side=BOTTOM)
    >>> bou2 = Button(fen1,text='Tracer une ligne',command-drawline)
      File "<stdin>", line 1
    SyntaxError: non-keyword arg after keyword arg
    >>> bou2.pack()
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    NameError: name 'bou2' is not defined
    >>> bou3 = Button (fen1,text ='Autre couleur' ,command=changecolor)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    NameError: name 'changecolor' is not defined
    >>> bou3.pack()
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    NameError: name 'bou3' is not defined
    >>> fen1.mainloop()
    >>> fen1.destroy()
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/lib/python2.5/lib-tk/Tkinter.py", line 1688, in destroy
        self.tk.call('destroy', self._w)
    _tkinter.TclError: can't invoke "destroy" command:  application has been destroyed
    >>>              
    ...

  3. #3
    Expert confirmé
    Avatar de Thierry Chappuis
    Homme Profil pro
    Enseignant Chercheur
    Inscrit en
    Mai 2005
    Messages
    3 499
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : Suisse

    Informations professionnelles :
    Activité : Enseignant Chercheur
    Secteur : Industrie Pharmaceutique

    Informations forums :
    Inscription : Mai 2005
    Messages : 3 499
    Par défaut
    Quelques erreurs d'inattention en copiant le programme:

    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
    # -*- coding: utf-8 -*-
     
    from Tkinter import*
    from random import randrange
     
    def drawline():
        "Tracé d'une ligne dans le canevas can1"
        global x1, y1, x2, y2, coul
        can1.create_line(x1,y1,x2,y2,width=2,fill=coul)
     
        #modification des coordonnées pour la ligne suivante :
        y2, y1 = y2 + 10 , y1 - 10
     
    def changecolor():
        "changement aléatoire de la couleur du tracé"
        global coul
        pal=['purple','cyan','maroon','green','red','blue','orange','yellow']
        c = randrange(8)
        coul = pal[c]
     
    #---------------Pgm principal---------
    #les variables suivantes seront utilisées de manière globale :
    x1, y1, x2, y2 = 10, 190, 190, 10
    coul = 'dark green'
     
    #création du widget principal ("maitre") :
    fen1 = Tk()
    # création du widget "esclave":
    can1 = Canvas (fen1,bg='dark gray', height=200, width=200)
    can1.pack(side=LEFT)
    bou1= Button (fen1,text='Quitter',command=fen1.quit)
    bou1.pack(side=BOTTOM)
    bou2 = Button(fen1,text='Tracer une ligne',command=drawline)
    bou2.pack()
    bou3 = Button (fen1,text ='Autre couleur' ,command=changecolor)
    bou3.pack()
    fen1.mainloop()
    fen1.destroy()
    comme entre autre pal(c) au lieu de pal[c].

    Thierry
    "The most important thing in the kitchen is the waste paper basket and it needs to be centrally located.", Donald Knuth
    "If the only tool you have is a hammer, every problem looks like a nail.", probably Abraham Maslow

    FAQ-Python FAQ-C FAQ-C++

    +

  4. #4
    Membre à l'essai
    Profil pro
    Inscrit en
    Juillet 2008
    Messages
    4
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2008
    Messages : 4
    Par défaut merci
    Merci Thierry, outre quelque problème d'inatention de ma part j'ai confomdu le 1 et le l qui dans le cours ne se différencis que par la barre haute.

  5. #5
    Expert confirmé
    Avatar de Thierry Chappuis
    Homme Profil pro
    Enseignant Chercheur
    Inscrit en
    Mai 2005
    Messages
    3 499
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : Suisse

    Informations professionnelles :
    Activité : Enseignant Chercheur
    Secteur : Industrie Pharmaceutique

    Informations forums :
    Inscription : Mai 2005
    Messages : 3 499
    Par défaut
    Citation Envoyé par fedora9!!! Voir le message
    j'ai confomdu le 1 et le l qui dans le cours ne se différencis que par la barre haute.
    Cette confusion ne portait pas trop à conséquence, car elle était systématique.

    Thierry
    "The most important thing in the kitchen is the waste paper basket and it needs to be centrally located.", Donald Knuth
    "If the only tool you have is a hammer, every problem looks like a nail.", probably Abraham Maslow

    FAQ-Python FAQ-C FAQ-C++

    +

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. petit probleme en programmation modulaire .
    Par elmcherqui dans le forum C
    Réponses: 3
    Dernier message: 24/11/2008, 15h59
  2. petit programme = Petit probleme
    Par DEGARINTE dans le forum Administration système
    Réponses: 2
    Dernier message: 08/10/2007, 14h32
  3. petit probleme de programmation de memory
    Par Asmod_D dans le forum C++
    Réponses: 2
    Dernier message: 25/09/2007, 01h54
  4. Réponses: 1
    Dernier message: 15/03/2007, 20h16
  5. Réponses: 6
    Dernier message: 02/08/2006, 17h24

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