I am trying to create a virtual keyboard using Tkinter and I am trying to do something
analogous to the code supplied below. I am having trouble with understanding the lambda
construct in the code below, which from what I understand is the only way to go without having to write a button widget for every single letter that exists on the keyboard.
I have always understood that when you are using lambda
, you do something analogous to:
variable = lambda x: x+5
but in the supplied code further down, the Button
widget has a lambda
I have not seen before written like this:
command=lambda value=text: select(entry, value)
I have spent all day reading about lambda
, and I still cannot get this.
This is the code link:
How to call and close a virtual keyboard made by Tkinter using touchscreen display
Specifically this is the line I am having problems with:
tk.Button(window, text=text, width=width,
command=lambda value=text: select(entry, value),
padx=3, pady=3, bd=12, bg="black", fg="white", takefocus = False
).grid(row=y, column=x, columnspan=columnspan)