Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from guizero import App, Box, Text, Picture, info
- app = App(title="Os and Xs", width = 480, height = 320, bg=(204,204,204), layout ="grid")
- blank = "25fb.png"
- X = "274c.png"
- O = "2b55.png"
- def move1():
- if img_box1.image == blank:
- img_box1.image= img_turn.image
- if img_turn.image == X:
- img_turn.image=O
- else:
- img_turn.image=X
- else:
- info("illegal move","Sorry, that box is already taken!")
- def move2():
- if img_box2.image == blank:
- img_box2.image= img_turn.image
- if img_turn.image == X:
- img_turn.image=O
- else:
- img_turn.image=X
- else:
- info("illegal move","Sorry, that box is already taken!")
- def move3():
- if img_box3.image == blank:
- img_box3.image= img_turn.image
- if img_turn.image == X:
- img_turn.image=O
- else:
- img_turn.image=X
- else:
- info("illegal move","Sorry, that box is already taken!")
- def move4():
- if img_box4.image == blank:
- img_box4.image= img_turn.image
- if img_turn.image == X:
- img_turn.image=O
- else:
- img_turn.image=X
- else:
- info("illegal move","Sorry, that box is already taken!")
- def move5():
- if img_box5.image == blank:
- img_box5.image= img_turn.image
- if img_turn.image == X:
- img_turn.image=O
- else:
- img_turn.image=X
- else:
- info("illegal move","Sorry, that box is already taken!")
- def move6():
- if img_box6.image == blank:
- img_box6.image= img_turn.image
- if img_turn.image == X:
- img_turn.image=O
- else:
- img_turn.image=X
- else:
- info("illegal move","Sorry, that box is already taken!")
- def move7():
- if img_box7.image == blank:
- img_box7.image= img_turn.image
- if img_turn.image == X:
- img_turn.image=O
- else:
- img_turn.image=X
- else:
- info("illegal move","Sorry, that box is already taken!")
- def move8():
- if img_box8.image == blank:
- img_box8.image= img_turn.image
- if img_turn.image == X:
- img_turn.image=O
- else:
- img_turn.image=X
- else:
- info("illegal move","Sorry, that box is already taken!")
- def move9():
- if img_box9.image == blank:
- img_box9.image= img_turn.image
- if img_turn.image == X:
- img_turn.image=O
- else:
- img_turn.image=X
- else:
- info("illegal move","Sorry, that box is already taken!")
- header = Box(app, width=480, height=20, grid=[0,0,5,1])
- box1 = Box(app,width=72,height=72,border=1, grid=[0,1])
- box2 = Box(app,width=72,height=72,border=1, grid=[0,2])
- box3 = Box(app,width=72,height=72,border=1, grid=[0,3])
- box4 = Box(app,width=72,height=72,border=1, grid=[1,1])
- box5 = Box(app,width=72,height=72,border=1, grid=[1,2])
- box6 = Box(app,width=72,height=72,border=1, grid=[1,3])
- box7 = Box(app,width=72,height=72,border=1, grid=[2,1])
- box8 = Box(app,width=72,height=72,border=1, grid=[2,2])
- box9 = Box(app,width=72,height=72,border=1, grid=[2,3])
- spacer1 = Box(app,width=181,height=219, grid=[3,1,1,3])
- spacer2 = Box(app,width=80, height=146, grid=[4,1,1,2])
- turn = Box(app,width=80,height=73,grid=[4,3])
- header.bg=(0,0,0)
- #spacer1.bg=(255,0,0)
- #spacer2.bg=(255,0,0)
- txt_header=Text(header,text="Tic-Tac-Toe")
- txt_header.text_color=(255,255,255)
- txt_spacer2=Text(spacer2,align="bottom",text="Turn:")
- img_turn=Picture(turn,O)
- img_box1 = Picture(box1,"25fb.png")
- img_box2 = Picture(box2,"25fb.png")
- img_box3 = Picture(box3,"25fb.png")
- img_box4 = Picture(box4,"25fb.png")
- img_box5 = Picture(box5,"25fb.png")
- img_box6 = Picture(box6,"25fb.png")
- img_box7 = Picture(box7,"25fb.png")
- img_box8 = Picture(box8,"25fb.png")
- img_box9 = Picture(box9,"25fb.png")
- img_box1.when_clicked = move1
- img_box2.when_clicked = move2
- img_box3.when_clicked = move3
- img_box4.when_clicked = move4
- img_box5.when_clicked = move5
- img_box6.when_clicked = move6
- img_box7.when_clicked = move7
- img_box8.when_clicked = move8
- img_box9.when_clicked = move9
- app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement