#鼠标点击后传参数给函数
import tkinter
def handler(event, a, b, c):
‘‘‘事件处理函数‘‘‘
print("handler", a, b, c)
def handlerAdaptor(fun, **kwds):
‘‘‘事件处理函数的适配器,相当于中介,那个event是从那里来的呢,我也纳闷,这也许就是python的伟大之处吧‘‘‘
return lambda event,fun=fun,kwds=kwds: fun(event, **kwds)
if __name__ == ‘__main__‘:
root = tkinter.Tk()
btn = tkinter.Button(text=u‘按钮‘)
btn.bind("<Button-1>", handlerAdaptor(handler,a=1,b=2,c=3))
btn.pack()
root.mainloop()
#button 传递参数
import tkinter
def handler(a, b, c):
‘‘‘事件处理函数‘‘‘
print ("handler", a, b, c)
if __name__==‘__main__‘:
root = tkinter.Tk()
# 通过中介函数handlerAdapotor进行command设置
btn = Tkinter.Button(text=u‘按钮‘, command=lambda : handler(a=1, b=2, c=3))
btn.pack()
root.mainloop()
原文:https://www.cnblogs.com/hengkuamalu/p/11418310.html