Posted By

maturanti19 on 05/22/19


Tagged

a padajuca lopta zavod auticok


Versions (?)

padajuca lopta a zavod auticok


 / Published in: Python
 

vytvorte zavod dvoch auticok aby vypisalo ktore je prve a padajuca lopta

  1. import tkinter
  2. from random import *
  3.  
  4. canvas = tkinter.Canvas(height=600, width=800, bg='gainsboro')
  5. canvas.pack()
  6.  
  7. def lopta():
  8. canvas.delete('all')
  9. global y
  10. y=y+5
  11. r=25
  12. canvas.create_oval(100-r, y-r, 100+r, y+r, fill='skyblue', outline='')
  13. if y<570:
  14. canvas.after(100, lopta)
  15.  
  16. def posun():
  17. global x1, x2
  18. a1=randrange(3,15)
  19. x1=x1+a1
  20. canvas.move('car1', a1,0)
  21. a2=randrange(3,15)
  22. x2=x2+a2
  23. canvas.move('car2', a2, 0)
  24. if (x1<700)and (x2<700):
  25. canvas.after(100, posun)
  26. if x1>=700:
  27. canvas.create_text(600, 30, text='vyhral fialovy!')
  28. elif x2>=700:
  29. canvas.create_text(600,30, text='vyhral modry!')
  30.  
  31. canvas.create_line(730, 50, 730, 270)
  32. canvas.create_text(730, 30, text='CIEL')
  33.  
  34.  
  35. x1=20
  36. x2=20
  37. r=10
  38. canvas.create_rectangle(x1, 100, x1+50, 130, fill='lavender', outline='', tags='car1')
  39. canvas.create_oval(x1+10-r, 130-r, x2+10+r, 130+r, tags='car1', fill='black')
  40. canvas.create_oval(x1+35-r, 130-r, x2+35+r, 130+r, tags='car1', fill='black')
  41. canvas.create_rectangle(x2, 200, x2+50, 230, fill='skyblue', outline='', tags='car2')
  42. canvas.create_oval(x2+10-r, 230-r, x2+10+r, 230+r, tags='car2', fill='black')
  43. canvas.create_oval(x2+35-r, 230-r, x2+35+r, 230+r, tags='car2', fill='black')
  44.  
  45. y=20
  46. #lopta()
  47. posun()

Report this snippet  

You need to login to post a comment.