【发布时间】:2013-03-27 12:55:03
【问题描述】:
我提出这个问题是因为我刚刚看到了这个问题What are the limitations of callback functions associated with Tkinter traces?。
我使用lambda 添加另一个参数。
代码如下:
from tkinter import *
def callbackfunc(*args, **kwargs):
print(args,kwargs)
class App(object):
def __init__(self, master):
frame = Frame(master)
frame.pack()
optionvalue = IntVar(master)
optionvalue.set(2)
optionvalue.trace("w",lambda a,b,c,x='test':callbackfunc(x))
self.optionmenu = OptionMenu(master, optionvalue, 1, 2, 3, 4)
self.optionmenu.pack()
root = Tk()
app = App(root)
root.mainloop()
我的输出:('test',) {}
我想知道的是:
如果我使用 lambda,为什么不输出其他 3 个参数?
【问题讨论】:
标签: python python-3.x callback tkinter