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)
Answer from Antti Haapala on Stack Overflow
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ tkinter-button-commands-with-lambda-in-python
Tkinter button commands with lambda in Python
March 5, 2021 - Lamda Functions (also referred ... any function that works as an anonymous function for expressions. In Button Command, lambda is used to pass the data to a callback function....
Discussions

windows - What does a lambda prompt indicate at the command line? - Stack Overflow
I just installed Cmder on a Windows box as a precursor to getting Cygwin installed and a bash shell going. It's my first time installing it, and I notice the prompt character used is lambda 'ฮป'. I'm More on stackoverflow.com
๐ŸŒ stackoverflow.com
Understanding Python Lambda behavior with Tkinter Button - Stack Overflow
I would like to understand how a button is working using lambda. I have the following Python code: from tkinter import * def comando_click(mensagem): print(mensagem) menu_inicial = Tk() More on stackoverflow.com
๐ŸŒ stackoverflow.com
Tkinter button command using lambda to call a class method - how???
command=self.open_notebook will work, and is a better than using lambda in my opinion. You also need to move most of the code under def __init__ rather than where it is. class MainWidget: def __init__(self): root = Tk() root.geometry("400x400") search_frame = Frame(root) search_frame.pack() self.search_function = SearchFunction(search_frame) open_notebook_button = Button(root, text="Open", command=self.open_notebook) open_notebook_button.pack() root.mainloop() def open_notebook(self): self.search_function.get_emp_id() # and more stuff to add later More on reddit.com
๐ŸŒ r/Tkinter
4
4
September 11, 2022
What exactly is "lambda" in Python? - Stack Overflow
What exactly is lambda in Python? And where and why is it used? More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
CodersLegacy
coderslegacy.com โ€บ home โ€บ python โ€บ using lambda with โ€˜commandโ€™ in tkinter
Using lambda with 'command' in Tkinter - CodersLegacy
January 25, 2022 - Basically we โ€œnestโ€ the function we want to call, within the lambda function. So in essence, we clicking the button triggers the lambda function which triggers the actual function we meant to call. def func(): print("I have been clicked!") button= Button(frame, text= "Click Me!", command= lambda: func())
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ using-lambda-in-gui-programs-in-python
Using lambda in GUI programs in Python - GeeksforGeeks
April 28, 2025 - from tkinter import * # functions def greet(value): print(value) # update Label text in GUI output_label["text"] = value if __name__ == "__main__": root = Tk() root.title("GFG") root.geometry("800x400") # GUI Heading Label(root, text="Using lambda in GUI programs in Python", font="calibre 28 bold", padx=5, pady=15).pack() # Button Button(root, text="Click me to Greet", command=lambda: greet( "Hello User"), bd=5, fg="blue", font="calibre 18 bold").pack() output_label = Label( root, text="", font="calibre 28 bold", padx=5, pady=15) output_label.pack() root.mainloop()
Find elsewhere
Top answer
1 of 3
1

When you use () with a function name(func(args)), then it is immediately calling/invoking the function while python is executing the line, you do not want that. You want to ONLY call the function when the button is clicked. tkinter will internally call the function for you, all you have to do is give the function name.

Why use lambda? Think of it as a function that returns another function, your code can be lengthened to:

func  = lambda: comando_click("Nova_Mensagem")
botao = Button(menu_inicial, text = "Executar", command=func)

func is the function name and if you want to call it, you would say func(). And when you say command=comando_click("Nova_Mensagem") then command has the value returned by command click(because you call the function with ()), which is None and if I'm not wrong, if the given value is None, it will not be called by tkinter. Hence your function is executed just once because of () and as a result of calling the function, you are assigning the value of the function call(None) before the event loop starts processing the events.

Some other methods:

  • Using partial from functools:
from functools import partial

botao = Button(.....,command=partial(comando_click,"Nova_Mensagem"))
  • Using a helper function:
def helper(args):
    def comando_click():
        print(args)

    return comando_click

botao = Button(...., command=helper("Nova_Mensagem"))

IMO, lambdas are the easiest way to proceed with calling a function with arguments.

2 of 3
1

In this code:

command=comando_click("Nova_Mensagem")

you have called the comando_click function, once, and assigned the result (None) to the command argument. Nothing will happen when command is called (in fact you should get a TypeError exception because None is not callable).

In this code:

command=lambda:comando_click("Nova_Mensagem")

you have not actually called comando_click yet -- you have created a new function (using lambda) that will in turn call comando_click when it is called. Every time the button is clicked, your new function will get called.

If the lambda is confusing, you can do the exact same thing with a def like this:

def button_command():
    comando_click("Nova_Mensagem")

...

command=button_command  # no ()!  we don't want to actually call it yet!

The lambda expression is just an alternative to using def when you want to create a small single-use function that doesn't need a name (e.g. you want to make a function that calls another function with a specific argument, exactly as you're doing here).

๐ŸŒ
Reddit
reddit.com โ€บ r/tkinter โ€บ tkinter button command using lambda to call a class method - how???
r/Tkinter on Reddit: Tkinter button command using lambda to call a class method - how???
September 11, 2022 -

I'm stuck, what am I missing?

Not sure if it's classes or tkinter that I don't correctly understand.

If I run the example below and hit the button I get "missing argument (self)". I totally get that.

class MainWidget:
    root = Tk()
    root.geometry("400x400")

    def open_notebook(self):
        self.search_function.get_emp_id()
        # and more stuff to add later

    search_frame = Frame(root)
    search_frame.pack()
    search_function = SearchFunction(search_frame)

    open_notebook_button = Button(root, text="Open", command=open_notebook)
    open_notebook_button.pack()

    root.mainloop()

Then I tried:

command=lambda: open_notebook()

... but it doesn't know open_notebook.

command=lambda: self.open_notebook()

... it doesn't know self

command=lambda: root.open_notebook()

... and it doesn't know root.

As I am playing around more with this I realize I have no idea if I maybe need a contructor and what difference exactly that would make, what goes in it (no pun intended) and what doesn't. I have no experience with OOP beyond the very very basics.

I'm grateful for any advice!

๐ŸŒ
Real Python
realpython.com โ€บ python-lambda
How to Use Python Lambda Functions โ€“ Real Python
December 1, 2023 - In this step-by-step tutorial, you'll learn about Python lambda functions. You'll see how they compare with regular functions and how you can use them in accordance with best practices.
๐ŸŒ
Python Programming
pythonprogramming.net โ€บ passing-functions-parameters-tkinter-using-lambda
Passing functions with Parameters in Tkinter using Lambda
Command is where you can pass functions, but here we're going to pass a lambda function instead, which creates a quick throwaway function, using the parameters we've set.
๐ŸŒ
Amazon Web Services
docs.aws.amazon.com โ€บ aws lambda โ€บ developer guide โ€บ what is aws lambda?
What is AWS Lambda? - AWS Lambda
January 31, 2026 - Lambda runs your code on a high-availability compute infrastructure and manages all the computing resources, including server and operating system maintenance, capacity provisioning, automatic scaling, and logging.
๐ŸŒ
Dataquest
dataquest.io โ€บ blog โ€บ tutorial-lambda-functions-in-python
Lambda Functions in Python (With Examples)
2 days ago - A lambda function is an anonymous function, meaning it doesn't have a name.
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ python-lambda-functions
Python Lambda Functions โ€“ How to Use Anonymous Functions with Examples
February 24, 2023 - Lambda functions, also known as anonymous functions, are small, one-time-use functions in Python. You can define them using the lambda keyword followed by the function's inputs, a colon, and the function's expression.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ can someone explain lambda to a beginner?
r/learnpython on Reddit: can someone explain lambda to a beginner?
October 10, 2024 -

I am a beginner and I do not understand what lambda means. Can explain to me in a simple way?

Top answer
1 of 16
100
It's a function that has no name, can only contain one expression, and automatically returns the result of that expression. Here's a function named "double": def double(n): return 2 * n print(double(2)) results in: 4 You can do the same thing without first defining a named function by using a lambda instead - it's creating a function right as you use it: print((lambda n: 2 * n)(2)) You can pass functions into other functions. The map function applies some function to each value of a sequence: list(map(double, [1, 2, 3])) results in: [2, 4, 6] You can do exactly the same thing without having defined double() separately: list(map(lambda n: 2 * n, [1, 2, 3]))
2 of 16
33
Before we delve into the topic, I wanted to make something clear about lambdas: YOU DO NOT EVER HAVE TO USE THEM! Lambdas are more of an intermediate Python topic and they don't have any inherent functionality that you can't do with a standard function. If you are having trouble reasoning about them, don't worry about it, and just use regular functions instead. Python allows you to do everything you'd want for a lambda with regular functions, it's just a matter of how concise and readable something might be. With all that being said, lambdas are anonymous functions. This means the function has no "name" and is instead assigned to a value or variable. For example, this is a "normal" function: def foo(a, b): return a + b In this case, you've defined a function called foo that takes two parameters and returns those parameters added together. Pretty standard. A lambda, on the other hand, is not defined on program start: foo = lambda a, b: a + b These are 100% equivalent: you can call them using the same syntax. So why would you ever use a lambda? In Python, a function can be used anywhere a lambda could be, but lambdas are often used when you want the definition of the function to be in line with its use. Lambdas tend to be used when you want to use functional programming design in Python (or other languages that support them), as you can "chain" these types of functions to create complex behavior that makes sense in a simple way when reading it. Where this really comes in handy is when you want to do things like sort or filter list data. For example, let's say you have a list of numbers, and want to only get the numbers over 100. You could write a function: my_list = [10, 150, 75, 100, 450, -20] def over_one_hundred(lst): new_lst = [] for num in lst: if num >= 100: new_lst.append(num) return new_lst print(over_one_hundred(my_list)) # Output [150, 100, 450] This works, but is a lot of code for something fairly common and simple. A list comprehension also works in this case: def over_one_hundred(lst): return [l for l in lst if l >= 100] print(over_one_hundred(my_list)) Much more compact, but still requires either a function or a fairly verbose list comprehension. And without a comment, it's not necessarily obvious at a glance the purpose of this list comprehension. It also only works on lists What if we instead use Python's filter function? This takes a sequence, which includes lists, but also includes dictionaries or other similar structures, plus a function that determines what is used for filtering. This is a perfect place for a lambda: over_one_hundred = list(filter(my_list, lambda x: x >= 100)) The list portion here is important, because it actually isn't evaluated immediately. This is a big advantage of sequences vs. lists or dictionaries...you only evaluate them when you are actually iterating over the items. This means they will generally have better performance, and it can make a large difference on huge data sets. But you could, for example, do a for loop over the result of the filter (without list), and if you break early, the check won't be done for the rest of the items. It's a subtle distinction, but if you get in the habit of using things like map, filter, reduce, etc. on sequences you can "compose" otherwise complex logic (like our original function!) into much smaller pieces that work in an intuitive manner, and you don't need to create a bunch of one-line functions for each step. This last portion is especially useful; sometimes you'll want a simple calculation throughout a function, but you don't need it elsewhere; if you define it as a lambda inside the function, you can call it multiple times without needing external helper functions that don't do a lot. If you don't get it all at first, that's fine, but hopefully I broke it down enough that you get an idea of why you might use these. I've personally found learning new concepts is easier if I understand the purpose behind them, but if that's too much, the basic idea is that lambda is a function that you define at the point you want to use it, and essentially is just a parameter list with a return statement. If you ever find yourself writing one-line functions that just return something, consider whether or not they make more sense as a lambda.
๐ŸŒ
TechTarget
techtarget.com โ€บ whatis โ€บ definition โ€บ lambda-general-definition
What is lambda (general definition)? | Definition from TechTarget
A lambda function in the versatile coding language of Python is a type of function that doesn't have a specific name and is usually used for simple tasks. It can accept multiple arguments, but it can only perform a single expression.
๐ŸŒ
Python.org
discuss.python.org โ€บ python help
What is the purpose of Lambda expressions? - Python Help - Discussions on Python.org
December 8, 2021 - This is a typical example for beginners: x=lambda n:2*n print(x(7)) Otherwise I would create a function: def dbl(n): return 2*n print(dbl(7)) Of course: I can write simply 2*7, but the idea is to save a complex formula in an object once, and reuse it several times.