Pouknouki

Untitled

Feb 11th, 2016
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. from tkinter import *
  2. from random import randrange, randint
  3.  
  4. x=randint(0, 200)
  5. y=randint(0, 200)
  6. r=15
  7. mult = 1
  8. mult2 = 1
  9.  
  10. mouvement = False
  11.  
  12. def demarrer():
  13. global mouvement
  14. if mouvement == False:
  15. mouvement = True
  16. else:
  17. mouvement = False
  18.  
  19. def deplace():
  20. global x, y, mouvement, mult, mult2
  21.  
  22. if mouvement==True:
  23. if(y + 15) >= 200:
  24. mult *= -1
  25. if (y - r) <= 0 and mult==1:
  26. mult *= -1
  27. y -= mult * 5
  28.  
  29. if (x + 15) >= 200:
  30. mult *= -1
  31. if (x - r) <= 0 and mult2==1:
  32. mult *= -1
  33. x += mult * 5
  34. can.coords(oval, x - mult2 * r, y - mult * r, x + mult2 * r, y + mult * r)
  35. fen.after(25,deplace)
  36.  
  37.  
  38. fen = Tk()
  39. can = Canvas(fen, bg='white', height=200, width=200)
  40. can.pack(side=RIGHT)
  41. bout1 = Button(fen,text='Quitter',command=fen.destroy)
  42. bout1.pack(side=BOTTOM) #Comme Christine Boutin
  43.  
  44. boutonDemarrer = Button(fen, text='Demarrer',command=demarrer)
  45. boutonDemarrer.pack(side=TOP)
  46.  
  47. c=['red','green','blue','yellow','orange']
  48. i=randrange(5)
  49. oval = can.create_oval(x-r, y-r, x+r, y+r, fill=c[i], outline=c[i])
  50. fen.after(50,deplace)
  51. fen.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment