在tkinter变量中胜出

时间:2018-01-22 19:53:31

标签: python python-3.x tkinter winsound

我在Tkinter做了一个刽子手游戏,每个字母都有按钮,每个按钮都链接到一个函数,该函数将处理这封信并告诉我它是否正确。如何使一个功能正确的声音和不正确的声音,我不想说我从哪里获取我的wav文件,因为它将移动(它将始终与我的程序在同一个文件中)。我不想要下载另一个模块,而另一个问题的答案不起作用。谢谢先进,

我试过这个,但它没有发出声音:

def no():
    lambda: PlaySound('wrong.wav', SND_FILENAME)
def yes():
    lambda: PlaySound('right.wav', SND_FILENAME)

1 个答案:

答案 0 :(得分:0)

您似乎不清楚lambda做了什么:

  

Python supports the creation of anonymous functions (i.e. functions that are not bound to a name) at runtime, using a construct called "lambda".

在您给出的示例中,您没有创建任何匿名函数,因此它们完全没必要。只需删除它们,一切都应该有效。

def no():
    PlaySound('wrong.wav', SND_FILENAME)
def yes():
    PlaySound('right.wav', SND_FILENAME)

请记住,winsound仅适用于Windows(因此没有跨平台开发)并且您需要使用这些功能from winsound import *

相关问题