我正在使用import winsound
,只想听一次winsound.PlaySound("ending.mp3", winsound.SND_ALIAS)
,但它会重复
if health == 0:
maxYhedefler = 0
maxZhedefler = 0
speed = 0
sınır1.penup()
sınır1.hideturtle()
sınır1.setposition(-360, 0)
bittistring = "You died,Score:",skor2
sınır1.write(bittistring, False, align="left", font=("Arial", 30, "normal"))
winsound.PlaySound("bitis.mp3", winsound.SND_ALIAS)
那是我使用的那条线,请帮助我! 最佳答案
将winsound.PlaySound("ending.mp3", winsound.SND_ALIAS)
更改为winsound.PlaySound("ending.mp3", winsound.SND_FILENAME)
。或者,尝试使用playsound
代替:
from playsound import playsound
if health == 0:
maxYhedefler = 0
maxZhedefler = 0
speed = 0
sınır1.penup()
sınır1.hideturtle()
sınır1.setposition(-360, 0)
bittistring = "You died,Score:",skor2
sınır1.write(bittistring, False, align="left", font=("Arial", 30, "normal"))
playsound("bitis.mp3")
如果
if
语句在while
循环内,则在played = False
循环上方添加while
,然后:if health == 0:
maxYhedefler = 0
maxZhedefler = 0
speed = 0
sınır1.penup()
sınır1.hideturtle()
sınır1.setposition(-360, 0)
bittistring = "You died,Score:",skor2
sınır1.write(bittistring, False, align="left", font=("Arial", 30, "normal"))
if not played:
playsound("bitis.mp3")
played = True
关于python - 如何添加声音并仅听1次,而不是反复听。 ( python ),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/62918178/