简体   繁体   中英

Python3 tkinter multiple arguments

I now know that to make a widget with tkinter with a command parameter with an argument I use lambda to do it. (eg Button(root, text="button", command=lambda: function(argument)) )

But what if I want to pass in multiple arguments, or in my case right now two arguments? When I just put it as lambda: function(argument1, argument2) , it gives me an error saying:

TypeError: <lambda>() takes no arguments (1 given)

How should I do this?

The way of using lambdas with several arguments is:

lambda arg1, arg2: function(arg1, arg2)

see some examples here and here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM