0

我正在尝试编写一个简单的音乐播放器。由于某种原因,在我选择了一个 mp3 文件并点击播放按钮后,没有声音出现。没有错误,什么都没有。它似乎直接跳过了命令。任何人都知道它为什么会这样做?如果有更好的用 python 播放音乐的方法,它是什么?

from win32com.client import Dispatch

import Tkinter
import tkFileDialog

class PlayerWin (Tkinter.Tk) :
    def __init__ (self) :
        self.Dir = None


        Tkinter.Tk.__init__(self)


        Tkinter.Button(self, text='File', command=self.select_file ).pack()

        Tkinter.Button(self, text=' ► ', command=self.play ,font=('Arial', 10 ,'bold')).pack()


    def select_file (self) :
        _dir = tkFileDialog.askopenfilename()
        self.Dir = _dir

    def play (self) :

        mp = Dispatch('WMPlayer.OCX')

        if self.Dir != None :
            print self.Dir
            song = mp.newMedia(self.Dir)
            mp.currentPlaylist.appendItem(song)
            mp.controls.play()



if __name__ == '__main__' :
    PlayerWin().mainloop()
4

1 回答 1

0

这可能与线程有关。

无论如何,还有其他适用于 Python 的 GUI 工具包,例如 WxPython,还有一些用 Python 编写的 mp3 播放器应用程序可供您学习。

于 2011-05-10T07:15:20.967 回答