For my first project, I'm working on building a soundboard using a Raspberry Pi as the base. I would like to have several buttons, each of which plays a random sound file from different lists on each press.
I'm using several built in libraries, specifically pygame, glob, random, and Button to make things easier. Glob is being used to generate a list of possible files to play, and random is being used to pick one of them.
pygame.init()
h = glob.glob('/file path/*.wav')
btn_0 = Button(2)
btn_0.when_pressed = pygame.mixer.Sound(random.choice(h)).play
From my admittedly basic understanding, this should call up a list of all files ending in .wav from the specific file path, and on the button press, randomly pick one to play through pygame.
What it is doing, though, is randomly picking a file from the list, and then playing that on a press. When I restart and run the code again, a different file is picked, so I know the list is being seen correctly.
Am I just missing something very obvious? Should I be using a different method? I'm just lost here.