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