Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from guizero import App, TextBox, PushButton, Box, Combo, CheckBox, Slider, MenuBar, info
- go="X"
- def winner_check():
- global board
- #rows check
- for i in range (3):
- print (sum(board[i]))
- if sum(board[i])==3:
- message.value="win for x in row "
- if sum(board[i])==12:
- message.value="win for O in row "
- #column check
- for col in range (3):
- tot=0
- for row in range (3):
- tot+=board[row][col]
- if tot==3:
- message.value="win for x"
- if tot==12:
- message.value="win for O"
- diag=board[0][0]+board[1][1]+board[2][2]
- diag2=board[0][2]+board[1][1]+board[2][0]
- if diag==3 or diag2==3:
- message.value="Diagonal WIN for X"
- if diag==12 or diag2==12:
- message.value="Diagonal WIN for O"
- def newgame():
- #this will refill the board with zeros
- #reset all the buttons to the numbers
- global board
- board=[[0,0,0],[0,0,0],[0,0,0]]
- print (board)
- for i in range (3):
- for j in range(3):
- z=a[i][j]
- z.text="."
- message.value="Player X to play!"
- def pr(arg):
- global go
- global board
- global a
- x=arg[0]
- y=arg[1]
- z=a[x][y]
- if z.text==".":
- z.text=go
- if go=="X":
- go="O"
- board[y][x]=1
- message.value="O to play"
- else:
- go="X"
- board[y][x]=4
- message.value="X to play"
- #z.text=board[y][x]
- winner_check()
- app=App("title")
- a=[[0,0,0],[0,0,0],[0,0,0]]
- board=[[0,0,0],[0,0,0],[0,0,0]]
- mybox=Box(app,layout="grid", width="600",height="600")
- mycol="red"
- for row in range(3):
- for col in range(3):
- mybox2=Box(mybox,grid=[col,row],width="200",height="200")
- a[col][row]=PushButton(mybox2,text=".",args=[[col,row]],command=pr)
- message=TextBox(app,text="Player X Play", width="fill")
- new=PushButton(app,text="New", command=newgame)
- app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement