scipiguy

FutureLearn GUIzero - TicTacToe

Nov 12th, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.78 KB | None | 0 0
  1. from guizero import App, PushButton
  2.  
  3. def tl_press():
  4.     if top_left.text == "O":
  5.         top_left.text = "X"
  6.     else:
  7.         top_left.text = "O"
  8.  
  9. def tm_press():
  10.     if top_mid.text == "O":
  11.         top_mid.text = "X"
  12.     else:
  13.         top_mid.text = "O"
  14.  
  15. def tr_press():
  16.     if top_right.text == "O":
  17.         top_right.text = "X"
  18.     else:
  19.         top_right.text = "O"
  20.  
  21. def ml_press():
  22.     if mid_left.text == "O":
  23.         mid_left.text = "X"
  24.     else:
  25.         mid_left.text = "O"
  26.  
  27. def mm_press():
  28.     if mid_mid.text == "O":
  29.         mid_mid.text = "X"
  30.     else:
  31.         mid_mid.text = "O"
  32.  
  33. def mr_press():
  34.     if mid_right.text == "O":
  35.         mid_right.text = "X"
  36.     else:
  37.         mid_right.text = "O"
  38.  
  39. def bl_press():
  40.     if bot_left.text == "O":
  41.         bot_left.text = "X"
  42.     else:
  43.         bot_left.text = "O"
  44.  
  45. def bm_press():
  46.     if bot_mid.text == "O":
  47.         bot_mid.text = "X"
  48.     else:
  49.         bot_mid.text = "O"
  50.  
  51. def br_press():
  52.     if bot_right.text == "O":
  53.         bot_right.text = "X"
  54.     else:
  55.         bot_right.text = "O"
  56.  
  57. app = App(layout="grid", title="TIC-TAC-TOE", width=140, height=132)
  58.  
  59. top_left = PushButton(app, text="...", grid=[0,0], command=tl_press)
  60. top_mid = PushButton(app, text="...", grid=[1,0], command=tm_press)
  61. top_right = PushButton(app, text="...", grid=[2,0], command=tr_press)
  62.  
  63. mid_left = PushButton(app, text="...", grid=[0,1], command=ml_press)
  64. mid_mid = PushButton(app, text="...", grid=[1,1], command=mm_press)
  65. mid_right = PushButton(app, text="...", grid=[2,1], command=mr_press)
  66.  
  67. bot_left = PushButton(app, text="...", grid=[0,2], command=bl_press)
  68. bot_mid = PushButton(app, text="...", grid=[1,2], command=bm_press)
  69. bot_right = PushButton(app, text="...", grid=[2,2], command=br_press)
  70.  
  71. app.display()
Add Comment
Please, Sign In to add comment