Python Tkinter Lambda Multiple Variable

Question:

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!

Asked By: vakacjus

||

Answers:

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)
Answered By: figbeam

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]))
Answered By: SomeMosa

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:

Answered By: Cntt Lâm Gia Bảo
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.