Advertisement
xavicano

Untitled

Aug 20th, 2019
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.52 KB | None | 0 0
  1. import os
  2. from random import shuffle, randint
  3. from guizero import App, Box, Picture, PushButton
  4. # set the path to the emoji folder on your computer
  5. emojis_dir = "C:\\Users\\xavi.cano\\Code\\emojis\\emojis"
  6.  
  7.  
  8. # create a list of the locations of the emoji images
  9. emojis = [os.path.join(emojis_dir, f) for f in os.listdir(emojis_dir) if os.path.isfile(os.path.join(emojis_dir, f))]
  10.  
  11.  
  12. # shuffle the emojis
  13. shuffle(emojis)
  14.  
  15.  
  16. app = App("emoji match")
  17. # create a box to house the grid
  18. pictures_box = Box(app, layout="grid")
  19.  
  20. # create a box to house the grids
  21. game_box = Box(app)
  22. # create a box to house the pictures
  23. pictures_box = Box(game_box, layout="grid")
  24. # create a box to house the buttons
  25. buttons_box = Box(game_box, layout="grid")
  26.  
  27.  
  28. buttons = []
  29. pictures = []
  30. # create 9 PushButtons with a different grid coordinate and add to the list
  31. for x in range(0,3):
  32.     for y in range(0,3):
  33.         # put the pictures and buttons into the lists
  34.         picture = Picture(pictures_box, grid=[x,y])
  35.         pictures.append(picture)
  36.  
  37.         button = PushButton(buttons_box, grid=[x,y])
  38.         buttons.append(button)
  39.  
  40.  
  41. ## for each picture in the list
  42. for picture in pictures:
  43.     ## make the picture a random emoji
  44.     picture.image = emojis.pop()
  45.  
  46. for button in buttons:
  47.       # make the image feature of the PushButton a random emoji
  48.       button.image = emojis.pop()  
  49.      
  50. random_button = randint(0,8)
  51. random_picture = randint(0,8)
  52. buttons[random_button].image=pictures[random_picture].image
  53.    
  54.  
  55. app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement