我刚刚开始使用带有GUI界面的python。我一直在用TKinter在一个简单的定时器程序上做实验。我被卡住了,因为我想用一首歌来播放警报,但一直没能找到解决办法。我正在研究linuxmint。我有一个消息窗口,当时间到了,我想启动音频与窗口,当你退出窗口,音频停止。我的代码是这样的。在from Tkinter import *
import tkMessageBox
def messageWindow():
win = Toplevel()
b = Button(win, text='Times Up!',
bg="yellow", fg="green",
activebackground="purple", activeforeground="white",
command=quit)
b.pack(ipadx=root.winfo_screenwidth()/2,
ipady=root.winfo_screenheight()/2)
root.mainloop()
def alert():
#this is were i would a call the function to play mp3
messageWindow()
quit()
def start():
root.after(scale.get() * 1000, alert)
root = Tk()
minutes = Label(root, text ="Minutes: ")
minutes.grid(row=0, column=0)
scale = Scale(root, from_=1, to=60, orient=HORIZONTAL, length=450)
scale.grid(row=0, column=1)
button = Button(root,text= "Start Timing", command=start)
button.grid(row=1, column=1, pady=5, sticky=E)
root.mainloop()