Advertisement
gordonc

emoji picture display

Aug 18th, 2019
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.98 KB | None | 0 0
  1. # emoji game
  2. from guizero import App, Text, Box, Picture, PushButton
  3. import os
  4. from random import shuffle
  5.  
  6. # initialisations
  7. xrange=4
  8. yrange=4
  9.  
  10. # set the path to the emoji folder on your computer
  11. emojis_dir = "emojis"
  12.  
  13. # create a list of the locations of the emoji images
  14. emojis = [os.path.join( emojis_dir, f) for f in os.listdir(emojis_dir) if os.path.isfile(os.path.join(emojis_dir, f))]
  15. # the above will pull in any file name e.g. thumbsnail so needs to be filtered. will not happen often with 1000 files
  16.  
  17. # shuffle the emojis
  18. shuffle(emojis)
  19.  
  20. app = App("emoji match")
  21.  
  22. # create a box to house the grid
  23. pictures_box = Box(app, layout="grid")
  24.  
  25. # create list for picture
  26. pictures = []
  27. for x in range(0,xrange):
  28.     for y in range(0,yrange):
  29.         # put the pictures into the list
  30.         picture = Picture(pictures_box, grid=[x,y])
  31.         pictures.append(picture)
  32.  
  33. i = 0
  34. for picture in pictures:
  35.     picture.image = emojis[i]
  36.     i = i + 1
  37.  
  38. app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement