Posted By

maturanti19 on 05/22/19


Tagged

python bind na pocet scitalka stvorcekov siet kruzok


Versions (?)

Vnoreny cyklus, scitalka, siet podla zadavatela


 / Published in: Python
 

Vytrvorte siet podla toho kolko si uzivatel zada stvorcekov aby sa tam dali po kliknuti kruzky a scitalka

  1. import tkinter
  2. from random import *
  3.  
  4. canvas = tkinter.Canvas(height=500, width=500, bg='gainsboro')
  5. canvas.pack()
  6.  
  7.  
  8. def vypis():
  9. for i in range (1,6):
  10. for j in range(1,11):
  11. canvas.create_text(j*15,i*15, text=str(j))
  12.  
  13. def scitalka(n):
  14. for i in range(1,n+1):
  15. for j in range(1, n+1):
  16. canvas.create_text(j*15,i*15, text=str(j+i))
  17.  
  18. pocet=int(input('Zadaj pocet cisel na scitalku: '))
  19. scitalka(pocet)
  20.  
  21. def siet(n):
  22. r=25
  23. d=2*r
  24. for i in range(1,n+1):
  25. for j in range(1,n+1):
  26. canvas.create_rectangle(j*d,i*d,j*d+d,i*d+d)
  27.  
  28. pocetn=int(input('Zadaj pocet stvorcekov na siet: '))
  29. siet(pocetn)
  30.  
  31.  
  32. def kruzok(sur):
  33. d=50
  34. x=sur.x - sur.x%d
  35. y=sur.y - sur.y%d
  36. canvas.create_oval(x,y,x+d,y+d, outline='blue', width=4)
  37. canvas.bind('<Button-1>', kruzok)

Report this snippet  

You need to login to post a comment.