Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- from random import shuffle,randrange
- from guizero import App, Box, Picture, Text
- # set the path to the emoji folder on your computer
- emojis_dir = "emojis"
- # create a list of the locations of the emoji images
- emojis = [os.path.join(emojis_dir, f) for f in os.listdir(emojis_dir) if os.path.isfile(os.path.join(emojis_dir, f))]
- # shuffle the emojis
- shuffle(emojis)
- blank = "25fb.png"
- #print(emojis)
- app = App("Emoji Match Game",width=720, height=480)
- def leftselected(event_data):
- pic_clicked = event_data.widget
- pictures[9].image = pic_clicked.image
- def rightselected(event_data):
- pic_clicked = event_data.widget
- pictures[10].image = pic_clicked.image
- # create a box to house the grid
- pictures_box = Box(app, layout="grid")
- header=Text(pictures_box, text="Emoji Match Game", size=28, grid=[0,0,8,1])
- # create an empty list to which pictures will be added
- pictures = []
- for x in range(0,3):
- for y in range(1,4):
- # put the pictures into the list
- picture = Picture(pictures_box, grid=[x,y])
- pictures.append(picture)
- picture = Picture(pictures_box, grid=[3,4])
- pictures.append(picture)
- picture = Picture(pictures_box, grid=[4,4])
- pictures.append(picture)
- for x in range(5,8):
- for y in range(1,4):
- # put the pictures into the list
- picture = Picture(pictures_box, grid=[x,y])
- pictures.append(picture)
- # for each picture in the list
- counter = 0
- for picture in pictures:
- # make the picture a random emoji
- pictures[counter].image = emojis[counter]
- counter=counter+1
- pictures[9].image = blank
- pictures[10].image = blank
- sourcepic = randrange(0,9)
- copypic = randrange(11,20)
- pictures[copypic].image = pictures[sourcepic].image
- P1_label=Text(pictures_box, text="Player 1\nScore:", size=10, align="right",grid=[0,4])
- P1_score=Text(pictures_box, text="xxxx", size=20, align="left", grid=[1,4])
- P2_label=Text(pictures_box, text="Player 2\nScore:", size=10, align="right",grid=[5,4])
- P2_sore=Text(pictures_box, text="xxxx", size=20, align="left", grid=[6,4])
- for count in range(0,9):
- pictures[count].when_clicked = leftselected
- for count in range(11,20):
- pictures[count].when_clicked = rightselected
- #print(emojis)
- app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement