import os from random import shuffle, randint from guizero import App, Box, Picture, Text, PushButton, warn # 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) def match_emoji(matched): if matched: result.value = "Correct" else: result.value = "Incorrect" setup_round() def setup_round(): global num_rounds 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(emojis) for picture in pictures: picture.image = emojis.pop() for button in buttons: button.image = emojis.pop() button.update_command(match_emoji, [False]) matched_emoji = emojis.pop() random_picture = randint(0,8) pictures[random_picture].image = matched_emoji random_button = randint(0,8) buttons[random_button].image = matched_emoji buttons[random_button].update_command(match_emoji, [True]) num_rounds = num_rounds + 1 rounds_played.value = "Round " +str(num_rounds) def counter(): global num_rounds timer.value = int(timer.value) - 1 if int(timer.value) == 0: timer.cancel(counter) result.value = "Game Over" warn("Time Up", "You have run out of time!") timer.value = 20 result.value = "" setup_round() timer.repeat(1000, counter) num_rounds = 0 num_rounds = 0 app = App("Emoji Match") result = Text(app) rounds_played = Text(app, text="Round " + str(num_rounds)) game_box = Box(app, layout="grid") # create a box to house the grid pictures_box = Box(game_box, layout="grid", grid=[0,0]) buttons_box = Box(game_box, layout="grid", grid =[1,0]) # create an empty list to which pictures will be added buttons = [] pictures = [] for x in range(0,3): for y in range(0,3): # put the pictures into the list picture = Picture(pictures_box, grid=[x,y]) pictures.append(picture) button = PushButton(buttons_box, grid=[x,y]) buttons.append(button) extra_features = Box(app) timer = Text(extra_features, text="Get Ready") setup_round() timer.value = 20 timer.repeat(1000, counter) app.display()