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
| from Tkinter import *
#definition des fonctions gestionnaires d'evenements
def creationdiagdeprod():
for i in nomposte:
listelabel['lab'+str(i)]=Label(fen1,text=x[4*i],relief=RAISED )
listelabel['lab'+str(i)].pack()
listecanvas['can'+str(i)]= Canvas(fen1,width=700,height=40,bg ='grey')
listecanvas['can'+str(i)].focus_set()
listecanvas['can'+str(i)].pack(padx=10,pady=10)
listelabel['lab'+str(i)].bind('<Button-1>',lambda event:creationcarre(event,i))
def creationcarre(event,i):
global nombrecarre
Hauteurcarre = 20
listecarre['carre'+str(nombrecarre)]=listecanvas['can'+str(i)].create_rectangle(0,0,x[3*i]*2,Hauteurcarre*2,fill='maroon')
nomcarre.append(nombrecarre)
nombrecarre+=1
print nomcarre
# Creation du widget principal :
fen1=Tk()
fen1.title("TIPE")
#variables et listes:
x=['A',455,3,2,'AA',524,25,1,'AAA',276,13,3]
nombrecarre=0
nomcarre=[]
nomposte=[0,1,2]
listecanvas={}
listelabel={}
listecarre={}
# creation des widgets :
bou2 = Button(fen1,text='Quitter',command=fen1.quit)
bou2.pack(side=BOTTOM)
bou3=Button(fen1,text='diag de prod',command=creationdiagdeprod)
bou3.pack()
fen1.mainloop() # demarrage du receptionnaire d'evenements
fen1.destroy() |
Partager