[英]i cant play sounds using winsound, in a function
我一直在嘗試制作一個假的核發射控制面板,我想播放一些聲音來配合按鈕。 我認為嘗試為單擊紅色大按鈕后出現的兩個按鈕添加聲音效果會很有趣,但它不起作用。
我試過做PlaySound("explosion.wav",SND_FILENAME)
然后winsound.PlaySound("exploion.wav",winsound.SND_FILENAME
但他們只是給了我:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\Nicholas Blundell\AppData\Local\Programs\Thonny\lib\tkinter\__init__.py", line 1705, in __call__
return self.func(*args)
File "C:\Users\Nicholas Blundell\Documents\documents backup\vol 4 - documents of post-now\code\python\multiple file programs\nukes\control panel for nucular launch.py", line 18, in fraud
winsound.PlaySound("attack.wav", winsound.SND_FILENAME )
NameError: name 'winsound' is not defined
然后它給了我這個:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\Nicholas Blundell\AppData\Local\Programs\Thonny\lib\tkinter\__init__.py", line 1705, in __call__
return self.func(*args)
File "C:\Users\Nicholas Blundell\Documents\documents backup\vol 4 - documents of post-now\code\python\multiple file programs\nukes\control panel for nucular launch.py", line 13, in win
winsound.PlaySound("Explosion3.wav", winsound.SND_FILENAME )
NameError: name 'winsound' is not defined
我的代碼:
def startkeypad():
def win():
label.delete(0,tk.END)
label.insert(0,"account vertified, nukes succesfully launched")
for i in range(10):
winsound.PlaySound("Explosion3.wav", winsound.SND_FILENAME )
sleep(0.25)
def fraud():
label.delete(0,tk.END)
label.insert(0,"account is fraud, nuke launch unsucesful")
winsound.PlaySound("attack.wav", winsound.SND_FILENAME )
buttonone = tk.Button(
text = "press either me or him",
bg = "yellow",
command = win
)
buttontwo = tk.Button(
text = "press either me or her",
bg = "green",
command = fraud
)
label = tk.Entry(
text = "press one of the buttons",
width = 50
)
buttonone.grid(row=3,column=1)
buttontwo.grid(row=3,column=3)
label.grid(row=3,column=2)
紐扣:
bigredlaunchbutton = tk.Button(
text = "LAUNCH NUKES",
command = startkeypad,
bg = "red",
width = 16,
height = 2,
)
您是否將 winsound 模塊導入到您的代碼中? 如果沒有,那么把它放在最上面: import winsound
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.