python: How can I remove lambda in this code?
If you want to remove lambda
from your code you must define a function return another function define
.
That is,
def replacement(): return define(argument)
This way you don't have to use lambda in calling Button
. Instead you would call Button
as :
auto = Button(root, text="auto", command=replacement).pack()
I hope this helps. But, you should learn what lambda's are.
You can also use partial
from functools
. It is basically the same as what @Suraj Upadhyay suggested.This is the code:
from tkinter import *from functools import partialdef define(a): passroot = Tk()function = partial(define, True) # The first arg is the function name and the rest are the function argsauto = Button(root, text="auto", command=function)auto.pack()