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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
| Python 3.2.1 (default, Jul 10 2011, 21:51:15) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> from tkinter import *
>>> def cercle(x, y, r, coul ='black'):
"tracé d'un cercle de centre (x, y) et de rayon r"
can.create_ocal(x-r, y-r, x+r, y+r, outline = coul)
>>> def figure_1():
"dessiner une cible"
# Effacer tout dessin préexistant :
can.delete(ALL)
# Tracer les deux lignes (vertic. et horiz.) :
can.create_line(100, 0, 100, 200, fill ='blue')
can.create_line(0, 100, 200, 100, fill ='blue')
# Tracer plusieurs cercles concentriques :
rayon = 15
while rayon < 100:
cercle(100, 100, rayon)
rayon += 15
>>> def figure_2():
"Dessiner un visage simplifié"
# Effacer tout dessin préexistant :
can.delete(ALL)
# Les caractéristiques de chaque cercle sont
# placées dans une liste de listes :
cc =[[100, 100, 80, 'red'], # visage
[70, 70, 15, 'blue'], # yeux
[130, 70, 15, 'blue'],
[70, 70, 5, 'black'],
[130, 70, 5, 'black'],
[44, 115, 20, 'red'],
[156, 115, 20, 'red'],
[100, 95, 15, 'purple'],
[100, 145, 30, 'purple']] # bouche
# on trace tous les cercles à l'aide d'une boucle :
i = 0
while i < len(cc): # parcours de la liste
el = cc[i] # chaque élément est lui-même une liste
cercle(el[0], el[1], el[2], el[3])
i +=1
>>> ##### Programme principal : ##########
>>>
>>> fen = Tk()
>>> can = Canvas(fen, width =200, height =200, 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()
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python32\lib\tkinter\__init__.py", line 1399, in __call__
return self.func(*args)
File "<pyshell#17>", line 11, in figure_1
File "<pyshell#4>", line 3, in cercle
AttributeError: 'Canvas' object has no attribute 'create_ocal'
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python32\lib\tkinter\__init__.py", line 1399, in __call__
return self.func(*args)
File "<pyshell#39>", line 20, in figure_2
File "<pyshell#4>", line 3, in cercle
AttributeError: 'Canvas' object has no attribute 'create_ocal'
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python32\lib\tkinter\__init__.py", line 1399, in __call__
return self.func(*args)
File "<pyshell#17>", line 11, in figure_1
File "<pyshell#4>", line 3, in cercle
AttributeError: 'Canvas' object has no attribute 'create_ocal'
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python32\lib\tkinter\__init__.py", line 1399, in __call__
return self.func(*args)
File "<pyshell#17>", line 11, in figure_1
File "<pyshell#4>", line 3, in cercle
AttributeError: 'Canvas' object has no attribute 'create_ocal'
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python32\lib\tkinter\__init__.py", line 1399, in __call__
return self.func(*args)
File "<pyshell#17>", line 11, in figure_1
File "<pyshell#4>", line 3, in cercle
AttributeError: 'Canvas' object has no attribute 'create_ocal' |