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
- # 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)
- #print(len(emojis))
- #functions
- def match_emoji(matched):
- if matched:
- result.value = "correctomondo!"
- else:
- result.value = "nope.."
- message = Text(app, len(emojis))
- set_up_round()
- def set_up_round():
- # 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)
- # for each picture in the list
- for picture in pictures:
- # make the picture a random emoji
- picture.image = emojis[1]
- emojis.remove(emojis[1])##emojis.pop()##
- for button in buttons:
- #add pictures to the buttons
- button.image= emojis[1]
- emojis.remove(emojis[1])
- button.update_command(match_emoji, [False])
- #select a random position index from the pictures
- rand_pict = randint(0,15)
- #select a random position index from the buttons
- rand_button = randint(0,15)
- #replace the button image with the one from the pictures
- buttons[rand_button].image = pictures[rand_pict].image
- buttons[rand_button].update_command(match_emoji, [True])
- buttons[rand_button].bg="yellow" # thanks to Stephen Carter
- pictures[rand_pict].bg="yellow" # thanks to Stephen Carter
- #print(emojis) - testing shuffling works
- #set up the app
- app = App("emoji match", width = 700, height = 500)
- #Add matching Text
- result = Text(app)
- # create a box to house the grid
- pictures_box = Box(app, layout="grid", align = "left")
- padder_box = Box(app, align="left", width = 50, height = 1)
- buttons_box = Box(app, layout="grid", align = "left")
- # create an empty list to which pictures will be added
- pictures = []
- for x in range(0,4):
- for y in range(0,4):
- # put the pictures into the list
- picture = Picture(pictures_box, grid=[x,y])
- pictures.append(picture)
- #create and empty list into which the butons will be added
- buttons = []
- for x in range (0,4):
- for y in range (0,4):
- # add the pictures to the list
- button = PushButton(buttons_box, grid=[x,y])
- buttons.append(button)
- set_up_round()
- # my method, pick one random picture from the pictures and replace a random image in the buttons
- ##print("picture master index", rand_pict)
- #print("button swapped", rand_button)
- #print(buttons[rand_button].image , pictures[rand_pict].image) # thanks to Stephen Carter
- #print(len(emojis))
- app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement