pygame - pygame中的自动声音回响(意外)
问题描述
我正在 Tkinter 和 pygame 中制作一个报时时钟。但是,它与整点的声音相呼应,这不是我想要的。如何让它只发出一次声音并且没有回声?注意:变量clock.chime 是chime 模式(1、2、3、off)的int,clock 是tkinter 的主窗口。这是我的代码:
while True:
try:
d = datetime.now() #updates time
hour = d.strftime("%I")
mins = d.strftime("%M")
secs = d.strftime("%S")
day = d.strftime("%A")
clock.update()
if mins=='00' and secs=='00' and clock.chime>0 and pygame.mixer.music.get_busy()==False: #chimes on the hour, but echoing
try:
pygame.mixer.music.load(str(clock.chime)+'.wav')
pygame.mixer.music.play()
except:
messagebox.showerror('Error', 'File '+str(clock.chime)+'.wav cannot be found.') #alerts if chime file is missing
time.sleep(0.01)
except: #detects when window is closed
break
解决方案
推荐阅读
- linux - 在 docker 下使用来自 Perl 的 capget syscall 和 capsh --drop=cap_sys_admin
- javascript - 使用多种变体过滤 MongoDB 集合
- javascript - 寻找任何替代状态管理工具来做出反应,而不是 redux
- python - 在 Python 中编写带有标题的阿拉伯语 rtf 文件
- ms-access - MS Access - 在查询中使用多选
- google-apps-script - Google App Scripts 在不变形的情况下删除重复项
- python - 在 Django Template For Selection 中同时迭代两个表 - Python Django
- wordpress - 调用未定义函数 wp()
- clang - 错误:为 aarch64_be 编译 compiler-rt ASAN 运行时时静态断言失败
- mysql - MYSQL用SUM减去两个表