I have been trying to figure this out for a while, and can't find a solution to why it won't work. I'm pretty new, and this is probably an easy fix, but this code:
from tkinter import * import pygame import os import random root = Tk() root.title('Hello') root.geometry('500x400') pygame.init() pygame.mixer.init() randomfile = random.choice(os.listdir("D:/Desktop/Plugin")) def play(): pygame.mixer.music.load(randomfile) pygame.mixer.music.play(loop=0) startButton = Button(root, text="Start", font=("Helvetica", 32), command=play) startButton.pack(pady=20) def stop(): pygame.mixer.music.stop() stopButton = Button(root, text="Stop", command=stop) stopButton.pack(pady=20) root.mainloop()Will always give me the error: pygame.error: Couldn't open 'audio2.mp3' I have 3 audio files in the folder and can't figure out why this wouldnt work.
Larz60+ write Feb-05-2021, 09:15 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use bbcode tags on future posts.
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use bbcode tags on future posts.