gpt4 book ai didi

python - Raspberry Pi和Python(TKinter和Omxplayer)

转载 作者:行者123 更新时间:2023-12-03 02:08:03 26 4
gpt4 key购买 nike

我们在python中制作了一个闹钟程序,当当前时间等于用户设置的闹钟时间时,该程序使用TKinter来显示单词“ALARM”。现在,我们正在尝试向程序中添加警报声音,以便在当前时间达到警报时间设置时播放声音。
由于某些奇怪的原因,当当前时间到达警报时间时,警报声音会立即打开并播放大约7次,然后退出。
我们尝试了几种不同的方法来使它仅播放一次声音文件,但没有任何效果。你们有什么建议吗?如果需要,我可以发布更多具体信息/屏幕截图。 :)

到目前为止的代码:

import time
import subprocess

#GUI Setup
from Tkinter import *
alarm_window = Tk()
alarm_window.configure(bg = 'lightblue')
alarm_window.title('Alarm Clock!')

display = Label(alarm_window, font = ('Arial', 25), bg = 'lightblue', width = 13, height = 1, borderwidth = 2)
display.grid(row = 1, column = 1, columnspan = 6)

current_time = time.strftime("%H:%M:%S")

def refresh_time():
global current_time
current_time = time.strftime("%H:%M:%S")

if current_time == times.get():
alarm_window.configure(bg='red')
timelabel.configure(bg='red')
alarmdisplay = Label(alarm_window, font = ('Arial', 25), text = 'ALARM', bg='red', width = 13, height = 1, borderwidth = 2,)
alarmdisplay.grid(row = 2, column = 1, columnspan = 6)

playProcess = subprocess.Popen(['omxplayer', '/home/pi/Digital Alarm.mp3?dl=0'])

display.config(text=current_time)
display.after(10, refresh_time)

timelabel = Label(alarm_window, text = 'Enter H:M:S', bg = 'lightblue')
timelabel.grid(row = 2, column = 1)
times = Entry(alarm_window, width = 10, bg = 'lightgrey', justify = CENTER)
times.grid(row = 2, column = 2, columnspan = 5)

times.focus()

refresh_time()
alarm_window.mainloop()

最佳答案

不知道omxplayer,但是如果在播放声音后退出,您可以简单地等待它完成,例如:

playProcess = subprocess.Popen(['omxplayer', '/home/pi/Digital Alarm.mp3?dl=0'])
playProcess.wait()

关于python - Raspberry Pi和Python(TKinter和Omxplayer),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26422594/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com