the fallowing is a tic tak toe game code in python, can some one show me how i can make it in GUI form with a reset option and shows who wins at the end. like X win or O win?
board = " 1 | 2 | 3\n-----------\n 4 | 5 | 6\n-----------\n 7 | 8 | 9"
. checkboard=[1,2,3,4,5,6,7,8,9,1,4,7,2,5,8,3,6,9,1,5,9,3,5,7]
spaces=range(1,10)
def moveHandler(board,spaces,checkboard,player,n):
if player==1:
check="X"
else:
check="O"
while spaces.count(n)==0:
print "\nInvalid Space"
n=playerinput(player)
spaces=spaces.remove(n)
board=board.replace(str(n),check)
for c in range(len(checkboard)):
if checkboard[c]==n:
checkboard[c]=check
status = checkwinner(checkboard,check)
return board,status
def checkwinner(checkboard,check): a,b,c=0,1,2
while a<=21:
combo = [checkboard[a],checkboard[b],checkboard[c]]
if combo.count(check) == 3:
status =1
break
else:
status =0
a+=3
b+=3
c+=3
return status
def playerinput(player): try: key = int(raw_input('\n\nPlayer ' + str(player) + ': Please select a space '))
except ValueError:
print "Invalid Space"
key = playerinput(player)
return key
while True:
player = len(spaces)%2 +1
if player == 1:
player = 2
else:
player =1
print "\n\n" + board
key = playerinput(player)
board,status =moveHandler(board,spaces,checkboard,player,key)
if status == 1:
print '\n\nPlayer ' + str(player) + ' is the winner!!!'
print board
break
elif len(spaces)==0:
print "No more spaces left. Game ends in a TIE!!!"
print board
break
else:
continue