音乐播放器应用

时间:2019-01-26 09:10:16

标签: python tkinter pygame mixer

我正在使用python构建一个简单的音乐播放器。但是,单击“播放”按钮后,我将无法播放歌曲,但单击“停止”消息后,终端上将显示退出代码为0的处理结束

from tkinter import *
from pygame import mixer

window = Tk()

mixer.init()

window.geometry('300x300')  # set dimension of the window
window.title('Music Player')  # title of the window

textLabel = Label(window, text="Play Button")
textLabel.pack()

def play_song():
    mixer.music.load('Particula.mp3')
    mixer.music.play()
def stop_song():
    mixer.music.stop()

play_photo = PhotoImage(file='play.png')
playButton = Button(window, image=play_photo, command=play_song)
playButton.pack()
stop_photo = PhotoImage(file='stop.png')
stopButton = Button(window, image=stop_photo, command=stop_song)
stopButton.pack()
window.mainloop()  # responsible for all kind of updation on the window

i have the music in the project directory

1 个答案:

答案 0 :(得分:0)

我已经导入了您的代码,并且可以在笔记本电脑上正常工作。我能够播放以及停止歌曲而不会出现任何错误。