In tkinter, for example, a control is associated with a function, such as a button.CodeAs follows:
Button = button (window, text = 'lowdown ', command = click)
Here, the click function is associated with the button plug-in, but it is difficult to pass parameters. Tkinter requires that controller functions triggered by buttons (or other plug-ins) do not contain parameters, so that they can be called in a unified manner. So how can we pass parameters to the function? This is often used. The answer is to use lambda.
Lambda allows us to create a single-row function without a name anywhere. The following is a simple example.
>>> Lambda: 3
<Function <Lambda> at 0x00a89930>
>>> (Lambda: 3 )()
3
The first expression creates an anonymous function. The function returns the result. 3. The second expression is created and the same function is executed immediately.
Lambda is a function parameter before the colon. Multiple parameters can be separated by commas. The return value is displayed on the right side of the colon.
The following is a Lambda function with parameters.
>>> (Lambda X: 2 * X) (3)
6
This can help us a lot in the GUI, so that our function controller can pass parameters. Take plug-in button as an Example
Button = button (window, text = 'lowdown ', command = lambda: Click (counter, 1 ))