Syn*_*pse 11 python arguments tkinter callback
我有两个按钮,分别命名为'ButtonA','ButtonB'.如果点击任何按钮,我希望程序打印'hello,ButtonA'和'hello,ButtonB'.我的代码如下:
def sayHi(name):
print 'hello,', name
root = Tk()
btna = Button(root, text = 'ButtonA', command = lambda: text)
btna.pack()
Run Code Online (Sandbox Code Playgroud)
当我单击ButtonA时,会发生错误,text not defined.
我理解这个错误,但是如何将ButtonA的文本传递给lambda?
Oca*_*tal 24
这应该工作:
...
btnaText='ButtonA'
btna = Button(root, text = btnaText, command = lambda: sayHi(btnaText))
btna.pack()
Run Code Online (Sandbox Code Playgroud)
有关更多信息,请查看Tkinter Callbacks
| 归档时间: |
|
| 查看次数: |
28346 次 |
| 最近记录: |