Advertisement
kalpin

Emojis 1

Aug 5th, 2020
1,231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.75 KB | None | 0 0
  1. import os
  2. from random import shuffle, randint
  3. from guizero import App, Box, Picture, PushButton, Text
  4.  
  5. GRID_SIZE = 3
  6.  
  7. # Event Handlers
  8.  
  9. def imageClick():
  10.     pass
  11.    
  12. # Load emoji library
  13. emojis_dir = "emojis"
  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. # shuffle the emojis
  16. shuffle(emojis)
  17.  
  18. # setup the app
  19. app = App("emoji match", width = GRID_SIZE*200, height = GRID_SIZE*100, bg = 'white')
  20.  
  21. # create a box to house the grids
  22. gameBox = Box(app)
  23. space = Box(gameBox, width = "fill", height = 60, align='top')
  24. lblInstruct = Text(space, text = 'Find the matching image!',height = 3)
  25.  
  26. # create a box to house the pictures
  27. picturesBox = Box(gameBox, layout="grid",align='left')
  28.  
  29. # create a box to house the buttons
  30. buttonsBox = Box(gameBox, layout="grid",align='left')
  31.  
  32. # create the an empty lists to add the buttons and pictures to
  33. buttons = []
  34. pictures = []
  35.  
  36. # create PushButtons with a different grid coordinate and add to the list
  37. for x in range(0,GRID_SIZE):
  38.     for y in range(0,GRID_SIZE):
  39.         # put the pictures and buttons into the lists
  40.         button = PushButton(picturesBox, grid=[x,y], command = imageClick)
  41.         pictures.append(button)
  42.  
  43.         button = PushButton(buttonsBox, grid=[x,y], command = imageClick)
  44.         buttons.append(button)
  45.  
  46. # for each picture and button in the list assign an emoji to its image feature
  47. for button in pictures:
  48.     button.image = emojis.pop()
  49.  
  50. for button in buttons:
  51.     button.image = emojis.pop()
  52.  
  53. # Select new image and place in both grids
  54. newImage = emojis.pop()
  55. buttons[randint(0,len(buttons)-1)].image = newImage
  56. pictures[randint(0,len(buttons)-1)].image = newImage
  57.  
  58. # Display app
  59. app.display()
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement