我刚开始使用带有 GUI 界面的 python。我一直在一个简单的计时器程序上试验 TKinter。我被卡住了,因为我想用警报播放一首歌,但找不到解决方案。我正在研究 Linux mint。我有一个消息窗口,时间到了就会出现,我想随着窗口一起启动音频,当你退出窗口时,音频停止。我的代码看起来像这样。
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()