How to Pass Arguments to Tkinter Button Command2 min read

command option in Tkinter Button widget is triggered when the user presses the button. In some scenarios, you need to pass arguments to the attached command function, but you couldn’t simply pass the arguments like below,

We will introduce two ways to pass the arguments to the command function.

Pass Arguments to command in Tkinter Button With partials

As demonstrated in Python Tkinter tutorial, you have the option to use the partial object from the functools module.

Pass Arguments to command in Tkinter Button With lambda Function

You could also use Python lambda operator or function to create a temporary, one-time simple function to be called when the Button is clicked.

The syntax of lambda function is

You don’t need any arguments in this example, therefore, you could leave the argument list empty and only give the expression.

Leave a Comment