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()