Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- from random import shuffle, randint
- from guizero import App, Box, Picture, PushButton
- # set the path to the emoji folder on your computer
- emojis_dir = "C:\\Users\\xavi.cano\\Code\\emojis\\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)
- app = App("emoji match")
- # create a box to house the grid
- pictures_box = Box(app, layout="grid")
- # create a box to house the grids
- game_box = Box(app)
- # create a box to house the pictures
- pictures_box = Box(game_box, layout="grid")
- # create a box to house the buttons
- buttons_box = Box(game_box, layout="grid")
- buttons = []
- pictures = []
- # create 9 PushButtons with a different grid coordinate and add to the list
- for x in range(0,3):
- for y in range(0,3):
- # put the pictures and buttons into the lists
- picture = Picture(pictures_box, grid=[x,y])
- pictures.append(picture)
- button = PushButton(buttons_box, grid=[x,y])
- buttons.append(button)
- ## for each picture in the list
- for picture in pictures:
- ## make the picture a random emoji
- picture.image = emojis.pop()
- for button in buttons:
- # make the image feature of the PushButton a random emoji
- button.image = emojis.pop()
- random_button = randint(0,8)
- random_picture = randint(0,8)
- buttons[random_button].image=pictures[random_picture].image
- app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement