johnpentyrch

GUI3p5

May 9th, 2020
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.48 KB | None | 0 0
  1. from guizero import App, PushButton, Box, Text, MenuBar
  2. # This is a mock up of my design for the Tic Tac Toe game.
  3. #It is not a fully functioning program but only to illustrate the design
  4. #You can see how it works by clicking on the top left square (as X) and then
  5. #the square to the right (as O). Then Click on bottom left square for X to win.
  6. #
  7. #The current player is show near the top of window. The Window is titled
  8. #'Tic Tac Toe'
  9.  
  10.  
  11. def dummy():
  12.     return
  13.  
  14. app = App(title='Tic Tac Toe', width=200, height=200)
  15. menubar = MenuBar(app,
  16.                   toplevel=["Game"],
  17. options=[
  18.                       [["New Game",dummy],["Save Result",dummy],["Exit",dummy]],
  19.                       ])
  20.  
  21.  
  22. global player
  23. player='X'
  24.  
  25. player_name = Text(app, text="Player X")
  26. def dummy():
  27.     return
  28.  
  29. #Box(file_controls, text="text_file.txt", width=50, align="left")
  30. def do_b1():
  31.     global player
  32.     if player == 'X':
  33.         player='O'
  34.         player_name.clear();
  35.         player_name.append('Player O')
  36.         button1.text='X'
  37.         button1.enabled=False
  38.     else:
  39.         player='X'
  40.         player_name.clear();
  41.         player_name.append('Player X')
  42.         button1.text='O'
  43.         button1.enabled=False
  44.  
  45. def do_b2():
  46.     global player
  47.     if player == 'X':
  48.         player='O'
  49.         player_name.clear();
  50.         player_name.append('Player O')
  51.         button2.text='X'
  52.         button2.enabled=False
  53.     else:
  54.         player='X'
  55.         player_name.clear();
  56.         player_name.append('Player X')
  57.         button2.text='O'
  58.         button2.enabled=False
  59.  
  60. def do_b7():
  61.     global player
  62.     if player == 'X':
  63.         player='O'
  64.         player_name.clear();
  65.         player_name.append('Player X wins!!!')
  66.         button7.text='X'
  67.         button7.enabled=False
  68.     else:
  69.         player='X'
  70.         player_name.clear();
  71.         player_name.append('Player X')
  72.         button7.text='O'
  73.         button7.enabled=False
  74.  
  75.  
  76.  
  77. box =Box(app, layout='grid')
  78.  
  79. button1 = PushButton(box, text="", grid=[0,0] , command=do_b1)
  80. button2 = PushButton(box, text="", grid=[1,0], command=do_b2)
  81. button3 = PushButton(box, text="", grid=[2,0])
  82. button4 = PushButton(box, text="X", grid=[0,1], enabled=False)
  83. button5 = PushButton(box, text="O", grid=[1,1], enabled=False)
  84. button6 = PushButton(box, text="", grid=[2,1])
  85. button7 = PushButton(box, text="", grid=[0,2] , command=do_b7)
  86. button8 = PushButton(box, text="", grid=[1,2])
  87. button9 = PushButton(box, text="", grid=[2,2])
  88.  
  89.  
  90. app.display()
Add Comment
Please, Sign In to add comment