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