Advertisement
Guest User

Untitled

a guest
Feb 18th, 2020
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. # tictactoe V1
  2. from guizero import App, Box, PushButton, Text
  3.  
  4. app = App(title="TicTacToe V1", width=600, height=500)
  5.  
  6. chosen = ""
  7.  
  8. def X_button():
  9. global chosen
  10. chosen = "X"
  11.  
  12. def O_button():
  13. global chosen
  14. chosen = "O"
  15.  
  16. def square_1():
  17. location = [0,0]
  18. mark=marked(location)
  19.  
  20. def square_2():
  21. location = [1,0]
  22. mark=marked(location)
  23.  
  24. def square_3():
  25. location = [2,0]
  26. mark=marked(location)
  27.  
  28. def square_4():
  29. location = [0,1]
  30. mark=marked(location)
  31.  
  32. def square_5():
  33. location = [1,1]
  34. mark=marked(location)
  35.  
  36. def square_6():
  37. global chosen
  38. location = [2,1]
  39. mark=marked(location)
  40.  
  41. def square_7():
  42. location = [0,2]
  43. mark=marked(location)
  44.  
  45. def square_8():
  46. location = [1,2]
  47. mark=marked(location)
  48.  
  49. def square_9():
  50. location = [2,2]
  51. mark=marked(location)
  52.  
  53. def marked(location):
  54. global chosen
  55. squared = Text(box1, text=chosen, grid=location, color="red", font="Times")
  56.  
  57.  
  58. box1 = Box(app, layout="grid", width=305, height=295, border=4)
  59. box1.text_size=25
  60.  
  61.  
  62. button1 = PushButton(box1, text="1", width="4", grid=[0,0], command=square_1)
  63. button2 = PushButton(box1, text="2", width="4", grid=[1,0], command=square_2)
  64. button3 = PushButton(box1, text="3", width="4", grid=[2,0], command=square_3)
  65. button4 = PushButton(box1, text="4", width="4", grid=[0,1], command=square_4)
  66. button5 = PushButton(box1, text="5", width="4", grid=[1,1], command=square_5)
  67. button6 = PushButton(box1, text="6", width="4", grid=[2,1], command=square_6)
  68. button7 = PushButton(box1, text="7", width="4", grid=[0,2], command=square_7)
  69. button8 = PushButton(box1, text="8", width="4", grid=[1,2], command=square_8)
  70. button9 = PushButton(box1, text="9", width="4", grid=[2,2], command=square_9)
  71.  
  72. box2 = Box(app, align="bottom", width="fill", border=True)
  73. message = Text(box2, text="Choose 'X' or 'O' then choose square ", size=15, align="left")
  74.  
  75. button_O = PushButton(box2, align="right", image="O_image.jpg", command=O_button)
  76.  
  77. button_X = PushButton(box2, align="right", image="X_image.jpg", command=X_button)
  78.  
  79.  
  80. app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement