Posted By

maturanti19 on 05/22/19


Tagged

python random Tkinter piskvorky tlacidla


Versions (?)

Piskvorky Tic tac toe


 / Published in: Python
 

Siet pocet okienok kolko urci uzivatel aj text co sa hybe podla stlacania klavesy

  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 siet():
  9. n=int(entry.get())
  10. global r
  11. r=25
  12. global d
  13. d=2*r
  14. for i in range(1,n+1):
  15. for j in range(1,n+1):
  16. canvas.create_rectangle(j*d,i*d,j*d+d,i*d+d)
  17.  
  18. global tah
  19. tah=1
  20. def kruzok1(sur):
  21. global tah
  22. if tah==1:
  23. d=50
  24. x=sur.x - sur.x%d
  25. y=sur.y - sur.y%d
  26. canvas.create_oval(x,y,x+d,y+d, outline='navy', width=4)
  27. canvas.create_text(200, 450, text='hrac 2')
  28. tah=tah*-1
  29. canvas.bind('<Button-1>', kruzok1)
  30.  
  31.  
  32. def kruzok2(sur):
  33. global tah
  34. if tah==-1:
  35. d=50
  36. x=sur.x - sur.x%d
  37. y=sur.y - sur.y%d
  38. canvas.create_oval(x,y,x+d,y+d, fill='navy', outline='', width=4)
  39. canvas.create_text(250, 450, text='hrac 1')
  40. tah=tah*-1
  41. canvas.bind('<Button-3>', kruzok2)
  42.  
  43. def zmaz():
  44. canvas.delete('all')
  45.  
  46. entry=tkinter.Entry()
  47. entry.pack()
  48.  
  49. def vymaz(k):
  50. canvas.delete('all')
  51.  
  52.  
  53. button=tkinter.Button(text='Zadaj pocet', command=siet)
  54. button.pack()
  55.  
  56. button2=tkinter.Button(text='Zacni znova', command=zmaz)
  57. button2.pack()
  58.  
  59. canvas.bind_all('k', vymaz)
  60.  
  61. x1=200
  62. y1=470
  63. canvas.create_text(x1,y1, text='Hrac 1 ma prazdny kruzok (lavy klik), hrac 2 ma plny kruzok (pravy klik)')
  64.  
  65. x2=200
  66. y2=490
  67. canvas.create_text(x2,y2, text='Ak chces ukoncit hru stlac tlacitko zacni znova alebo stlac klavesu k')

Report this snippet  

You need to login to post a comment.