我一直在尝试制作一个假的核发射控制面板,我想播放一些声音来配合按钮。我认为尝试为单击大红色按钮后出现的两个按钮添加声音效果会很有趣,但它就是行不通。
我试过这样做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,
)