Using the lambda function in 'command = ' from Tkinter. Using the lambda function in 'command = ' from Tkinter. tkinter tkinter

Using the lambda function in 'command = ' from Tkinter.


The command lambda does not take any arguments at all; furthermore there is no evt that you can catch. A lambda can refer to variables outside it; this is called a closure. Thus your button code should be:

bouton1 = Button(main_window, text="Enter",    command = lambda: get(Current_Weight, entree1))

And your get should say:

def get(loot, entree):    loot = float(entree.get())    print(loot)


Actually, you just need the Entry object entree1 as the lamda pass-in argument. Either statement below would work.

bouton1 = Button(main_window, text="Enter", command=lambda x = entree1: get(x))bouton1 = Button(main_window, text="Enter", command=lambda : get(entree1))

with the function get defined as

def get(entree):    print(float(entree.get()))