0

I'm a newbie at programming.

In python, tkinter, I want to generate a list of buttons by a function (clicked2). This function gets an array of class objects (worker) from another function.

I want to make a button for each object in the array and clicking that button should activate the function "influence" with that specific object.

Now. my following attempt results into an instant activation of the buttons.

btn = Button(window, text=obj.name + " "+ str(obj.rev_Value), command=influence(obj.no))  

I did some research I think a call back function + pack() is the solution , but I never used either lamba function or call back functions.

Nevertheless, that's my second attempts, which didn't work at all.

       btn = Button(window, text= str(obj.no)+" "+obj.name + " "+ str(obj.rev_Value)), command= lambda: influence(obj.no)).pack()

Here's the whole function "clicked2":


def clicked2():
    
   
    worker = create_worker_unit(int(txt2.get()))
  
    
    
    
    for obj in worker:
      
        
       
        btn = Button(window, text= str(obj.no)+" "+obj.name + " "+ str(obj.rev_Value)), command= lambda: influence(obj.no)).pack()
        #That's my first attempt, which resulted into instantly acitivated buttons
        #btn = Button(window, text=obj.name + " "+ str(obj.rev_Value), command=influence(obj.no))        


        btn.grid(column=1, row=5+worker.index(obj))

Thank you for any help

0 Answers0