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!
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)
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]))
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!
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)
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]))