Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- from random import shuffle
- from guizero import App, Box, Picture, PushButton
- # import the randint function
- from random import randint
- # set the path to the emoji folder on your computer
- emojis_dir = "/home/pi/Public/image"
- # 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)
- # setup the app
- app = App("emoji match")
- # 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")
- # create the an empty lists to add the buttons and pictures to
- 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 and button in the list assign an emoji to its image feature
- 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()# choose a new emoji
- # select two numbers at random for both picture and botton
- random_picture = randint(0,8)
- random_button = randint (0,8)
- # replace the image feature of the Picture by the of pictures to the randomly seclected emoji
- pictures[random_picture].image = buttons[random_button].image
- app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement