Advertisement
timber101

EmojisV2

Aug 16th, 2019
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.59 KB | None | 0 0
  1. import os
  2. from random import shuffle, randint
  3. from guizero import App, Box, Picture, PushButton
  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. #print(emojis) - testing shuffling works
  15.  
  16. app = App("emoji match", width = 500, height = 800)
  17. # create a box to house the grid
  18. pictures_box = Box(app, layout="grid")
  19. buttons_box = Box(app, layout="grid")
  20.  
  21. # create an empty list to which pictures will be added
  22. pictures = []
  23. for x in range(0,4):
  24.     for y in range(0,4):
  25.         # put the pictures into the list
  26.         picture = Picture(pictures_box, grid=[x,y])
  27.         pictures.append(picture)
  28.        
  29.  
  30. # for each picture in the list
  31. for picture in pictures:
  32.     # make the picture a random emoji
  33.     picture.image = emojis[1]
  34.     emojis.remove(emojis[1])##emojis.pop()##
  35. #print(len(emojis))
  36. #create and empty list into which the butons will be added
  37. buttons = []
  38. for x in range (0,4):
  39.     for y in range (0,4):
  40.         # add the pictures to the list
  41.         button = PushButton(buttons_box, grid=[x,y])
  42.         buttons.append(button)
  43.  
  44. #print(len(emojis))
  45. #print("buttons length",len(buttons))
  46.  
  47. for button in buttons:
  48.     button.image= emojis[1]
  49.     emojis.remove(emojis[1])
  50. '''    
  51. # replace one in each set to be the matcher
  52. matcher_emojis = emojis[1]
  53. emojis.remove(emojis[1])
  54.  
  55. #select a random position index from the pictures
  56. rand_pict = randint(0,15)
  57.  
  58. #change picture
  59. pictures[rand_pict].image = matcher_emojis
  60.  
  61. #select a random position index from the buttons
  62. rand_button = randint(0,15)
  63.  
  64. #change button picture
  65. buttons[rand_button].image = matcher_emojis
  66.  
  67. print("picture",rand_pict)
  68. print("button",rand_button)
  69. '''
  70.  
  71. # my method, pick one random picture from the pictures and replace a random image in the buttons
  72.  
  73.  
  74. #select a random position index from the pictures
  75. rand_pict = randint(0,15)
  76.  
  77. #select a random position index from the buttons
  78. rand_button = randint(0,15)
  79.  
  80.  
  81.  
  82. #replace the button image with the one from the pictures
  83. buttons[rand_button].image = pictures[rand_pict].image
  84.  
  85. print("picture master index", rand_pict)
  86. print("button swapped", rand_button)
  87. print(buttons[rand_button].image , pictures[rand_pict].image) # thanks to Stephen Carter
  88. buttons[rand_button].bg="green" # thanks to Stephen Carter
  89. pictures[rand_pict].bg="green" # thanks to Stephen Carter
  90.  
  91. #print(len(emojis))
  92.  
  93. app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement