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
|
# -*- coding:Utf8 -*-
# Exercice utilisant la bibliothèque graphique Tkinter
from Tkinter import *
import time, threading
def cercle(r, coul ='black'):
"tracé d'un cercle de centre (x,y) et de rayon r"
can.create_oval(300-r, 300-r, 300+r, 300+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 rayon < 290:
rayon += 15
cercle(rayon)
time.sleep(0.5)
##### Programme principal : ############
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() |
Partager