# -*- coding:Utf8 -*- # Exercice utilisant la bibliothèque graphique Tkinter from tkinter import * import time, threading 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) def figure_1(): "dessiner une cible" x=50 # 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 while x < 600: y= 2*x cercle(x, y, 1) sleep(0.5) x += 20 ##### Programme principal : ############ sleep (0.5) fen = Tk() can = Canvas(fen, width =600, height =600, bg ='ivory') can.pack(side =TOP, padx =5, pady =5) b1 = Button(fen, text ='dessin 1', command =figure_1) b1.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()