Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import*
- from random import*
- def chgt1_color():
- x1,y1=0,0
- x2,y2=500,500
- for i in range(4):
- cercleB = canvas.create_oval(x1, y1, x2, y2,fill='white')
- x1,y1= x1+30, y1+30
- x2,y2=x2-30,y2-30
- cercleW = canvas.create_oval(x1,y1,x2,y2,fill='black')
- x1,y1= x1+30, y1+30
- x2,y2=x2-30,y2-30
- def chgt2_color():
- x1,y1=0,0
- x2,y2=500,500
- liste=["blue","red","orange","green","purple","yellow","cyan","magenta","lime","aqua"]
- for i in range(4):
- cercleB = canvas.create_oval(x1, y1, x2, y2,fill=liste[randint(0,9)])
- x1,y1= x1+30, y1+30
- x2,y2=x2-30,y2-30
- cercleW = canvas.create_oval(x1,y1,x2,y2,fill=liste[randint(0,9)])
- x1,y1= x1+30, y1+30
- x2,y2=x2-30,y2-30
- def cercle1():
- global id
- canvas.after_cancel(id)
- canvas.delete(ALL)
- x1,y1=0,0
- x2,y2=500,500
- for i in range(4):
- cercleB = canvas.create_oval(x1, y1, x2, y2,fill='black')
- x1,y1= x1+30, y1+30
- x2,y2=x2-30,y2-30
- cercleW = canvas.create_oval(x1,y1,x2,y2,fill='white')
- x1,y1= x1+30, y1+30
- x2,y2=x2-30,y2-30
- id=canvas.after(1000,chgt1_color)
- id=canvas.after(2000,cercle1)
- def cercle2():
- global id
- canvas.after_cancel(id)
- canvas.delete(ALL)
- x1,y1=0,0
- x2,y2=500,500
- liste=["blue","red","orange","green","purple","yellow","cyan","magenta","lime","aqua"]
- for i in range(4):
- cercleB = canvas.create_oval(x1, y1, x2, y2,fill=liste[randint(0,9)])
- x1,y1= x1+30, y1+30
- x2,y2=x2-30,y2-30
- cercleW = canvas.create_oval(x1,y1,x2,y2,fill=liste[randint(0,9)])
- x1,y1= x1+30, y1+30
- x2,y2=x2-30,y2-30
- id=canvas.after(1000,chgt2_color)
- id=canvas.after(2000,cercle2)
- fen=Tk()
- canvas= Canvas(fen, height=500, width=500,bg='white')
- canvas.pack()
- frame= Frame(width=500, height=50)
- frame.pack(expand=TRUE)
- bouton1= Button(frame,text='dessin1',command=cercle1)
- bouton1.grid(column=1,row=1)
- bouton2 = Button(frame,text='dessin2',command=cercle2)
- bouton2.grid(column=2,row=1)
- fen.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement