Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.18 KB | None | 0 0
  1. from tkinter import*
  2. from random import*
  3.  
  4. def chgt1_color():
  5.     x1,y1=0,0
  6.     x2,y2=500,500
  7.     for i in range(4):
  8.             cercleB = canvas.create_oval(x1, y1, x2, y2,fill='white')
  9.             x1,y1= x1+30, y1+30
  10.             x2,y2=x2-30,y2-30
  11.             cercleW = canvas.create_oval(x1,y1,x2,y2,fill='black')
  12.             x1,y1= x1+30, y1+30
  13.             x2,y2=x2-30,y2-30
  14.  
  15. def chgt2_color():
  16.     x1,y1=0,0
  17.     x2,y2=500,500
  18.     liste=["blue","red","orange","green","purple","yellow","cyan","magenta","lime","aqua"]
  19.     for i in range(4):
  20.             cercleB = canvas.create_oval(x1, y1, x2, y2,fill=liste[randint(0,9)])
  21.             x1,y1= x1+30, y1+30
  22.             x2,y2=x2-30,y2-30
  23.             cercleW = canvas.create_oval(x1,y1,x2,y2,fill=liste[randint(0,9)])
  24.             x1,y1= x1+30, y1+30
  25.             x2,y2=x2-30,y2-30
  26.  
  27.  
  28. def cercle1():
  29.     global id
  30.     canvas.after_cancel(id)
  31.     canvas.delete(ALL)
  32.     x1,y1=0,0
  33.     x2,y2=500,500
  34.     for i in range(4):
  35.         cercleB = canvas.create_oval(x1, y1, x2, y2,fill='black')
  36.         x1,y1= x1+30, y1+30
  37.         x2,y2=x2-30,y2-30
  38.         cercleW = canvas.create_oval(x1,y1,x2,y2,fill='white')
  39.         x1,y1= x1+30, y1+30
  40.         x2,y2=x2-30,y2-30
  41.     id=canvas.after(1000,chgt1_color)
  42.     id=canvas.after(2000,cercle1)
  43.  
  44.  
  45. def cercle2():
  46.     global id
  47.     canvas.after_cancel(id)
  48.     canvas.delete(ALL)
  49.     x1,y1=0,0
  50.     x2,y2=500,500
  51.     liste=["blue","red","orange","green","purple","yellow","cyan","magenta","lime","aqua"]
  52.     for i in range(4):
  53.         cercleB = canvas.create_oval(x1, y1, x2, y2,fill=liste[randint(0,9)])
  54.         x1,y1= x1+30, y1+30
  55.         x2,y2=x2-30,y2-30
  56.         cercleW = canvas.create_oval(x1,y1,x2,y2,fill=liste[randint(0,9)])
  57.         x1,y1= x1+30, y1+30
  58.         x2,y2=x2-30,y2-30
  59.     id=canvas.after(1000,chgt2_color)
  60.     id=canvas.after(2000,cercle2)
  61.  
  62. fen=Tk()
  63.  
  64. canvas= Canvas(fen, height=500, width=500,bg='white')
  65. canvas.pack()
  66.  
  67. frame= Frame(width=500, height=50)
  68. frame.pack(expand=TRUE)
  69.  
  70. bouton1= Button(frame,text='dessin1',command=cercle1)
  71. bouton1.grid(column=1,row=1)
  72.  
  73. bouton2 = Button(frame,text='dessin2',command=cercle2)
  74. bouton2.grid(column=2,row=1)
  75.  
  76. fen.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement