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, Text
- GRID_SIZE = 3
- # Event Handlers
- def imageClick():
- pass
- # Load emoji library
- emojis_dir = "emojis"
- 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", width = GRID_SIZE*200, height = GRID_SIZE*100, bg = 'white')
- # create a box to house the grids
- gameBox = Box(app)
- space = Box(gameBox, width = "fill", height = 60, align='top')
- lblInstruct = Text(space, text = 'Find the matching image!',height = 3)
- # create a box to house the pictures
- picturesBox = Box(gameBox, layout="grid",align='left')
- # create a box to house the buttons
- buttonsBox = Box(gameBox, layout="grid",align='left')
- # create the an empty lists to add the buttons and pictures to
- buttons = []
- pictures = []
- # create PushButtons with a different grid coordinate and add to the list
- for x in range(0,GRID_SIZE):
- for y in range(0,GRID_SIZE):
- # put the pictures and buttons into the lists
- button = PushButton(picturesBox, grid=[x,y], command = imageClick)
- pictures.append(button)
- button = PushButton(buttonsBox, grid=[x,y], command = imageClick)
- buttons.append(button)
- # for each picture and button in the list assign an emoji to its image feature
- for button in pictures:
- button.image = emojis.pop()
- for button in buttons:
- button.image = emojis.pop()
- # Select new image and place in both grids
- newImage = emojis.pop()
- buttons[randint(0,len(buttons)-1)].image = newImage
- pictures[randint(0,len(buttons)-1)].image = newImage
- # Display app
- app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement