Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from guizero import App, PushButton, Box, Text, MenuBar
- # This is a mock up of my design for the Tic Tac Toe game.
- #It is not a fully functioning program but only to illustrate the design
- #You can see how it works by clicking on the top left square (as X) and then
- #the square to the right (as O). Then Click on bottom left square for X to win.
- #
- #The current player is show near the top of window. The Window is titled
- #'Tic Tac Toe'
- def dummy():
- return
- app = App(title='Tic Tac Toe', width=200, height=200)
- menubar = MenuBar(app,
- toplevel=["Game"],
- options=[
- [["New Game",dummy],["Save Result",dummy],["Exit",dummy]],
- ])
- global player
- player='X'
- player_name = Text(app, text="Player X")
- def dummy():
- return
- #Box(file_controls, text="text_file.txt", width=50, align="left")
- def do_b1():
- global player
- if player == 'X':
- player='O'
- player_name.clear();
- player_name.append('Player O')
- button1.text='X'
- button1.enabled=False
- else:
- player='X'
- player_name.clear();
- player_name.append('Player X')
- button1.text='O'
- button1.enabled=False
- def do_b2():
- global player
- if player == 'X':
- player='O'
- player_name.clear();
- player_name.append('Player O')
- button2.text='X'
- button2.enabled=False
- else:
- player='X'
- player_name.clear();
- player_name.append('Player X')
- button2.text='O'
- button2.enabled=False
- def do_b7():
- global player
- if player == 'X':
- player='O'
- player_name.clear();
- player_name.append('Player X wins!!!')
- button7.text='X'
- button7.enabled=False
- else:
- player='X'
- player_name.clear();
- player_name.append('Player X')
- button7.text='O'
- button7.enabled=False
- box =Box(app, layout='grid')
- button1 = PushButton(box, text="", grid=[0,0] , command=do_b1)
- button2 = PushButton(box, text="", grid=[1,0], command=do_b2)
- button3 = PushButton(box, text="", grid=[2,0])
- button4 = PushButton(box, text="X", grid=[0,1], enabled=False)
- button5 = PushButton(box, text="O", grid=[1,1], enabled=False)
- button6 = PushButton(box, text="", grid=[2,1])
- button7 = PushButton(box, text="", grid=[0,2] , command=do_b7)
- button8 = PushButton(box, text="", grid=[1,2])
- button9 = PushButton(box, text="", grid=[2,2])
- app.display()
Add Comment
Please, Sign In to add comment