Advertisement
timber101

EmojiV3

Aug 18th, 2019
371
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.01 KB | None
  1. import os
  2. from random import shuffle, randint
  3. from guizero import App, Box, Picture, PushButton, Text
  4.  
  5. # set the path to the emoji folder on your computer
  6. emojis_dir = "emojis"
  7. # create a list of the locations of the emoji images
  8. emojis = [os.path.join(emojis_dir, f) for f in os.listdir(emojis_dir) if os.path.isfile(os.path.join(emojis_dir, f))]
  9. # shuffle the emojis
  10. shuffle(emojis)
  11.  
  12. #print(len(emojis))
  13.  
  14. #functions
  15. def match_emoji(matched):
  16.     if matched:
  17.         result.value = "correctomondo!"
  18.     else:
  19.         result.value = "nope.."
  20.     message = Text(app, len(emojis))
  21.     set_up_round()
  22.  
  23. def set_up_round():
  24.    
  25.     # set the path to the emoji folder on your computer
  26.     emojis_dir = "emojis"
  27.     # create a list of the locations of the emoji images
  28.     emojis = [os.path.join(emojis_dir, f) for f in os.listdir(emojis_dir) if os.path.isfile(os.path.join(emojis_dir, f))]
  29.     # shuffle the emojis
  30.     shuffle(emojis)
  31.     # for each picture in the list
  32.     for picture in pictures:
  33.         # make the picture a random emoji
  34.         picture.image = emojis[1]
  35.         emojis.remove(emojis[1])##emojis.pop()##
  36.    
  37.    
  38.     for button in buttons:
  39.         #add pictures to the buttons
  40.         button.image= emojis[1]
  41.         emojis.remove(emojis[1])
  42.         button.update_command(match_emoji, [False])    
  43.  
  44.  
  45.  
  46.     #select a random position index from the pictures
  47.     rand_pict = randint(0,15)
  48.  
  49.     #select a random position index from the buttons
  50.     rand_button = randint(0,15)
  51.  
  52.     #replace the button image with the one from the pictures
  53.     buttons[rand_button].image = pictures[rand_pict].image
  54.  
  55.     buttons[rand_button].update_command(match_emoji, [True])
  56.     buttons[rand_button].bg="yellow" # thanks to Stephen Carter
  57.     pictures[rand_pict].bg="yellow" # thanks to Stephen Carter
  58.  
  59. #print(emojis) - testing shuffling works
  60.  
  61. #set up the app
  62. app = App("emoji match", width = 700, height = 500)
  63. #Add matching Text
  64. result = Text(app)
  65.  
  66.  
  67. # create a box to house the grid
  68.  
  69. pictures_box = Box(app, layout="grid", align = "left")
  70. padder_box = Box(app, align="left", width = 50, height = 1)
  71. buttons_box = Box(app, layout="grid", align = "left")
  72.  
  73.  
  74. # create an empty list to which pictures will be added
  75. pictures = []
  76. for x in range(0,4):
  77.     for y in range(0,4):
  78.         # put the pictures into the list
  79.         picture = Picture(pictures_box, grid=[x,y])
  80.         pictures.append(picture)
  81.        
  82.  
  83.  
  84.  
  85. #create and empty list into which the butons will be added
  86. buttons = []
  87. for x in range (0,4):
  88.     for y in range (0,4):
  89.         # add the pictures to the list
  90.         button = PushButton(buttons_box, grid=[x,y])
  91.         buttons.append(button)
  92.  
  93. set_up_round()
  94.  
  95. # my method, pick one random picture from the pictures and replace a random image in the buttons
  96.  
  97.  
  98.  
  99. ##print("picture master index", rand_pict)
  100. #print("button swapped", rand_button)
  101. #print(buttons[rand_button].image , pictures[rand_pict].image) # thanks to Stephen Carter
  102.  
  103.  
  104.  
  105. #print(len(emojis))
  106.  
  107. app.display()
Advertisement
RAW Paste Data Copied
Advertisement