Using Lambda and tuples to send to Multiple Functions: Python, Tkinter

二次信任 提交于 2019-12-02 06:02:57

On the line that you create your button, you can accomplish this either with a (stupid) lambda trick:

tk.Button(self,text=b[0],width=5,height=2, bg="grey", 
command=lambda text=b:[self.name(text[1]), self.info(text[2])] ).grid(row=r,column=c)

or define a separate function that calls both:

tk.Button(self,text=b[0],width=5,height=2, bg="grey", 
command=lambda text=b:self.call_both(text)).grid(row=r,column=c)

def call_both(self, line):
    self.name(line[1])
    self.info(line[2])
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!