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 :

Livre de Swinnen Exercice 8.13


Sujet :

Tkinter Python

  1. #1
    Membre à l'essai
    Inscrit en
    Novembre 2005
    Messages
    22
    Détails du profil
    Informations forums :
    Inscription : Novembre 2005
    Messages : 22
    Points : 10
    Points
    10
    Par défaut Livre de Swinnen Exercice 8.13
    Bonjour,
    je suis ce livre afin d'avoir les bases de python.
    Je suis à l'exercice 8.13 et je ne trouve pas comment comment transmettre le choix des cercles via un button.
    Un p'tit coup main ? Merci
    Voici le code :
    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
     
    #!/usr/bin/env python
    # -*- coding: latin1 -*-
     
    from Tkinter import *
     
    def place(event):
    	global ov
    	x = event.x
    	y = event.y
    	# can.coords(ov, x, y, x +30, y +30)
    	can.coords(ov, x, y)
     
    def select1():
    	ov = oval
    	return ov
     
    def select2():
    	ov = oval2
    	return ov
    #----------------
    x, y = 10, 10
    x2, y2 = 50, 10
    ov = 'oval'
     
    fen = Tk()
    fen.title("Exercice d'animation")
    can = Canvas(fen, bg='dark grey', height=300, width=300)
    can.pack(side=LEFT)
     
    oval = can.create_oval(x, y, x+30, y+30, width=2, fill='red')
    oval2 = can.create_oval(x2, y2, x2+30, y2+30, width=2, fill='green')
     
    can.bind("<Button-1>", place)
     
    Button(fen, text='Quitter', command=fen.quit).pack(side=BOTTOM)
    Button(fen, text='cercle rouge', command=select1).pack()
    Button(fen, text='cercle vert', command=select2).pack()
     
    fen.mainloop()

  2. #2
    Membre à l'essai
    Inscrit en
    Novembre 2005
    Messages
    22
    Détails du profil
    Informations forums :
    Inscription : Novembre 2005
    Messages : 22
    Points : 10
    Points
    10
    Par défaut
    Salut à tous,

    J'ai réussi cet exercice, c'est fou ce qu'une cote ou guillemet peuvent faire le bordel quand il sont mal utilisé. Bref content moi
    Allez je continue.

    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
     
    #!/usr/bin/env python
    # -*- coding: latin1 -*-
     
    from Tkinter import *
     
    def place(event):
    	global ov
    	if ov == 'oval':
    		x = event.x
    		y = event.y
    		can.coords(oval, x, y, x +30, y +30)
    	if ov =='oval2':
    		x2 = event.x
    		y2 = event.y
    		can.coords(oval2, x2, y2, x2 +30, y2 +30)
     
    def select1():
    	global ov
    	ov = 'oval'
     
    def select2():
    	global ov
    	ov = 'oval2'
    #----------------
    x, y = 10, 10
    x2, y2 = 50, 10
     
    ov = 'oval'
    fen = Tk()
    fen.title("Exercice d'animation")
    can = Canvas(fen, bg='dark grey', height=300, width=300)
    can.pack(side=LEFT)
     
    oval = can.create_oval(x, y, x+30, y+30, width=2, fill='red')
    oval2 = can.create_oval(x2, y2, x2+30, y2+30, width=2, fill='green')
     
    can.bind("<Button-1>", place)
     
    Button(fen, text='Quitter', command=fen.quit).pack(side=BOTTOM)
    Button(fen, text='cercle rouge', command=select1).pack()
    Button(fen, text='cercle vert', command=select2).pack()
     
    fen.mainloop()

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

Discussions similaires

  1. [Python 3.X] Swinnen exercice 10.32
    Par loncle dans le forum Général Python
    Réponses: 4
    Dernier message: 03/01/2015, 22h10
  2. Aide pour exercice livre "Apprendre à programmer en Python" par Swinnen
    Par reivilo1982 dans le forum Général Python
    Réponses: 4
    Dernier message: 28/02/2011, 12h35
  3. [Cours Swinnen][Tkinter] bloqué à un exercice
    Par babar89 dans le forum Tkinter
    Réponses: 4
    Dernier message: 18/10/2005, 16h48
  4. [cours de G.Swinnen] exercice 66
    Par airod dans le forum Tkinter
    Réponses: 4
    Dernier message: 14/10/2005, 11h02

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