1

Quick question. I have created a button like this:

LABEL = tkinter.Button(top, text ="GO 1", command = lambda *args: go('1'), width = 13, height=2)

So, I was wondering. How can I pass multiple values to definition using lambda in the button above?

def go(value):

Thanks!

6
  • 1
    You question is unclear. The command callback does not accept argument. What arguments do you want to pass to it? Commented Jul 11, 2018 at 7:42
  • lambda x = "1": go(x), Multiple type arguments are not supported (just one)! So go(list,str,str,int) never work, and all type definitions is uniterable(just use event or tag). Commented Jul 11, 2018 at 8:27
  • 1
    @dsgdfg: your comment isn't true. You can use multiple arguments with lambda. Commented Jul 11, 2018 at 12:00
  • True, but that depends on the condition. If an element is not in global reach (created by iteration), it is necessary to give it a single argument or use the tag name as a variable. As the number of arguments increases, probability and combinations also increase, which significantly extends the writing of code, causing additional performance loss (response time, system resources, etc.). @BryanOakley Commented Jul 13, 2018 at 8:47
  • @dsgdfg: yes, more arguments == more complexity. However, you said it was impossible. It's not impossible. Commented Jul 13, 2018 at 11:40

3 Answers 3

3

Put values in function call:

LABEL = tkinter.Button(top, text ="GO 1", command=lambda: go('1', 'a', True))

Then unpack the values in the function definition:

def go(*values):
    print(values)
Sign up to request clarification or add additional context in comments.

Comments

1

You could always use a tuple or a list like this:

def go(value):
    for val in value:
        print(val)

Create the button like this:

LABEL = tkinter.Button(top, text ="GO 1", command=lambda: go(('1', 'a', True)))

Or like this:

LABEL = tkinter.Button(top, text ="GO 1", command=lambda: go(['1', 'a', True]))

Comments

-1

Create a tuple and use it as a normal variable so you can add two or more variable in one tuple and transfer them with button:

1 Comment

Don't post images of code or links to images of code, embed the code in your answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.