Posted By

maturanti19 on 05/22/19


Tagged

pocet konfetti kruzkov podla uzivatela


Versions (?)

Konfetti a zadaj pocet kruzkov s tlacidlom sa pridaju a zaverecne titulky


 / Published in: Python
 

Uzivatel zada pocet kruzkov ktore sa vytvoria kliknutim na gombik a ked klikne len tak tak mu urobi jeden farebny kruzok akoze konfetti a zaverecne titulky ktore sa hybu smerom hore

  1. import tkinter
  2. from random import *
  3.  
  4. canvas = tkinter.Canvas(height=600, width=800, bg='gainsboro')
  5. canvas.pack()
  6.  
  7. def kruzok(suradnice):
  8. x=suradnice.x
  9. y=suradnice.y
  10. farba = choice(('thistle', 'skyblue', 'indigo', 'white', 'gray', 'violet', 'salmon'))
  11. canvas.create_oval(x-10, y-10, x+10, y+10, fill=farba, width=3)
  12.  
  13. def kruzky(n):
  14. for i in range(n):
  15. x=randrange(100,700)
  16. y=randrange(100,500)
  17. canvas.create_oval(x-20, y-20, x+20, y+20, outline='navy', width=2)
  18.  
  19. def kruhy():
  20. pocet=int(entry.get())
  21. kruzky(pocet)
  22.  
  23. def zmaz():
  24. canvas.delete('all')
  25.  
  26. def posun(parameter):
  27. canvas.delete('all')
  28. ## global x1 ak chcem aby sa pamatala premenna
  29. x1=200
  30. global y1
  31. y1=y1-5
  32. canvas.create_text(x1,y1, text='Zaverecne titulky')
  33.  
  34. #pocet= int(input('Zadaj pocet kruzkov: '))
  35.  
  36. entry=tkinter.Entry()
  37. entry.pack()
  38.  
  39. button=tkinter.Button(text='Zadaj pocet', command=kruhy)
  40. button.pack()
  41.  
  42. button2=tkinter.Button(text='Zmaz vsetko', command=zmaz)
  43. button2.pack()
  44.  
  45. x1=200
  46. y1=500
  47. canvas.create_text(x1,y1, text='Zaverecne titulky')
  48.  
  49. canvas.bind('<Button-1>', kruzok)
  50. canvas.bind_all('<Up>', posun)
  51.  
  52. #kruzky(pocet)

Report this snippet  

You need to login to post a comment.