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
| # -*- coding:Utf8 -*-
# Exercice utilisant la bibliothèque graphique Tkinter
from tkinter import *
def cercle(x, y, r, coul='black'):
"tracé d'un cercle de centre (x,y) et de rayon r"
can.create_oval(x-r, y-r, x+r, y+r, outline=coul)
if x < 600:
y = 2*x
x += 20
fen.after(500, lambda x=x, y=y, r=r: cercle(x, y, r))
def figure_1():
"dessiner une cible"
# Effacer d'abord tout dessin préexistant :
can.delete(ALL)
# tracer les deux lignes (vert. et horiz.) :
can.create_line(300, 0, 300, 600, fill='blue')
can.create_line(0, 300, 600, 300, fill='blue')
# tracer plusieurs cercles concentriques :
rayon = 15
x = 50
y = 2*x
cercle(x, y, rayon)
##### Programme principal : ############
fen = Tk()
can = Canvas(fen, width=600, height=600, bg='ivory')
can.pack(side=TOP, padx=5, pady=5)
Button(fen, text ='dessin 1', command =figure_1).pack(side=LEFT, padx=3, pady=3)
#b2 = Button(fen, text ='dessin 2', command =figure_2)
#b2.pack(side =RIGHT, padx =3, pady =3)
fen.mainloop() |
Partager