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

前端 未结 1 1807
名媛妹妹
名媛妹妹 2021-01-26 23:57
column1 = [
(\'H\', \'Hydrogen\', \'Atomic # = 1\\nAtomic Weight =1.01\\nState = Gas\\nCategory = Alkali Metals\'),
(\'Li\', \'Lithium\', \'Atomic # = 3\\nAtomic Weight          


        
相关标签:
1条回答
  • 2021-01-27 00:33

    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])
    
    0 讨论(0)
提交回复
热议问题