2014-10-04 75 views
0
import subprocess 

def musicplayer(): 
audio_file = "C:\\Python34\\Calvin.mp3" 

return_code = subprocess.call(["afplay", audio_file]) 

button2 = Button(root, text="Place Bet", command=musicplayer) 
button2.configure(background="darkred") 
button2.pack(anchor=E) 

我已经将音乐文件移动到python的更容易访问的区域,因为它以前没有工作过。我对编码相当陌生,只是试图让一些小程序进行。这是正确的吗?我不断收到错误:试图在程序中播放音乐 - 文件路径错误

"Exception in Tkinter callback 
Traceback (most recent call last): 
    File "C:\Python34\lib\tkinter\__init__.py", line 1487, in __call__ 
    return self.func(*args) 
    File "C:/Users/Michael/Documents/test 1.py", line 27, in musicplayer 
    return_code = subprocess.call(["afplay", audio_file]) 
    File "C:\Python34\lib\subprocess.py", line 537, in call 
    with Popen(*popenargs, **kwargs) as p: 
    File "C:\Python34\lib\subprocess.py", line 858, in __init__ 
    restore_signals, start_new_session) 
    File "C:\Python34\lib\subprocess.py", line 1111, in _execute_child 
    startupinfo) 
FileNotFoundError: [WinError 2] The system cannot find the file specified 

如果任何人都可以协助或告诉我放弃,那太棒了!

+0

什么/在哪里'afplay'? – 2014-10-04 15:47:01

+0

一个朋友添加了它,不知道为什么...删除它,现在得到错误:OSError:[WinError 193]%1不是有效的Win32应用程序 – Hagrid 2014-10-04 15:51:49

+0

那么,你需要某种库或可执行文件来播放音频文件。 'afplay'似乎只是一个OS X的应用程序,所以你甚至在你的Windows系统上都没有。 – 2014-10-04 15:54:20

回答

0

检查路径,文件名大小写,并可能使用原始字符串R“C:\ Python34 \ Calvin.mp3”

+0

检查所有的大小写和文件路径等与afplay删除我仍然得到错误:OSError:[WinError 193]%1不是有效的Win32应用程序和afplay回来我得到的错误:FileNotFoundError:[WinError 2]系统找不到指定的文件 – Hagrid 2014-10-04 15:54:47

+0

抱歉,看起来很难看... – Hagrid 2014-10-04 15:55:09

0

似乎afplay是不是在蟒蛇的路径,给的全路径afplay和您的脚本将工作

subprocess.call(["c:\\path\\to\\afplay.exe", audio_file])