Posted By

maturanti19 on 05/22/19


Tagged

random V nahodne obsah stvorca ciary strede kvadrantu


Versions (?)

random veci a stvorec s obsahom random stuff how to make


 / Published in: Python
 

Vytvorte nahodny stvorec vnutri bude jeho obsah

  1. import tkinter
  2. from random import *
  3.  
  4. canvas = tkinter.Canvas(height=600, width=800, bg='gainsboro')
  5. canvas.pack()
  6.  
  7. # tri random ciary
  8. canvas.create_line(randrange(0,800), randrange(0,600), randrange(0,800), randrange(0,600), fill='skyblue', width=3)
  9. canvas.create_line(randrange(0,800), randrange(0,600), randrange(0,800), randrange(0,600), fill='indigo', width=3)
  10. canvas.create_line(randrange(0,800), randrange(0,600), randrange(0,800), randrange(0,600), fill='lavender', width=3)
  11.  
  12. #tri ciary z rohu
  13. canvas.create_line(0, 0, randrange(0,800), randrange(0,600), fill='thistle', width=5)
  14. canvas.create_line(0, 0, randrange(0,800), randrange(0,600), fill='thistle', width=5)
  15. canvas.create_line(0, 0, randrange(0,800), randrange(0,600), fill='thistle', width=5)
  16.  
  17. #tri ciary zo stredu do kvadrantu
  18. canvas.create_line(400, 300, randrange(400,800), randrange(0,300), fill='black', width=4)
  19. canvas.create_line(400, 300, randrange(400,800), randrange(0,300), fill='black', width=4)
  20. canvas.create_line(400, 300, randrange(400,800), randrange(0,300), fill='black', width=4)
  21.  
  22. #tri male stvorce
  23. x=randrange(0,600)
  24. y=randrange(0,800)
  25. canvas.create_rectangle(x, y, x+20, y+20, outline='skyblue', width=3 )
  26.  
  27. x=randrange(0,600)
  28. y=randrange(0,800)
  29. canvas.create_rectangle(x, y, x+20, y+20, outline='indigo', width=3 )
  30.  
  31. x=randrange(0,600)
  32. y=randrange(0,800)
  33. canvas.create_rectangle(x, y, x+20, y+20, outline='violet', width=3 )
  34.  
  35. #stvorec s obsahom
  36. x=randrange(0,600)
  37. y=randrange(0,800)
  38. z=randrange(10,100)
  39. canvas.create_rectangle(x, y, x+z, y+z, fill='white', outline='')
  40. canvas.create_text(x+z//2, y+z//2, text=z*z)
  41.  
  42. x=randrange(0,600)
  43. y=randrange(0,800)
  44. z=randrange(10,100)
  45. canvas.create_rectangle(x, y, x+z, y+z, fill='white', outline='')
  46. canvas.create_text(x+z//2, y+z//2, text=z*z)
  47.  
  48. x=randrange(0,600)
  49. y=randrange(0,800)
  50. z=randrange(10,100)
  51. canvas.create_rectangle(x, y, x+z, y+z, fill='white', outline='')
  52. canvas.create_text(x+z//2, y+z//2, text=z*z)

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: jackwalton on May 29, 2019

awesome post. https://download9apps.com/

Posted By: jackwalton on May 29, 2019

awesome post <a href=">download free 9apps

You need to login to post a comment.