I am building a program for Windows PCs that contains a lot of buttons and seems very plain. So I was wondering, can I make it so when you push a button (using tkinter), can I play a sound to liven up the program a bit? Please keep in mind I am learning so please dumb it down a bit.
Assuming your file is a WAV:
from tkinter import *
from winsound import *
root = Tk() # create tkinter window
play = lambda: PlaySound('Sound.wav', SND_FILENAME)
button = Button(root, text = 'Play', command = play)
button.pack()
root.mainloop()
Assuming your file is a MP3:
from Tkinter import *
import mp3play
root = Tk() # create tkinter window
f = mp3play.load('Sound.mp3'); play = lambda: f.play()
button = Button(root, text = 'Play', command = play)
button.pack()
root.mainloop()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With