TKinter当Label绑定bind事件时传参方法


记录下tkinter的

当在label绑定bind事件时,遇到需要传参时的解决方法(因为有event存在 所以不能直接传参)

https://www.cnblogs.com/liyuanhong/articles/10718217.html

pic_list[i * 4 + j].bind("<Button-1>",handlerAdaptor(handler,res_list=result_list))



def handler(event,res_list):
    print(int(event.widget['text']))
    print(res_list)
    print("click", res_list[(int(event.widget['text']))])

def handlerAdaptor(fun,**kwds):
    return lambda event,fun=fun,kwds=kwds:fun(event,**kwds)

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM