[Python] Need help with simple graphical calculator program
Go to solution
Solved by Mr_KoKa,
In your example lambda is used for create small function really fast, so your:
bttn_0["command"] = lambda: op1.num_press(0);
is like:
def functionForButton0(): op1.num_press(0);bttn_0["command"] = functionForButton0;
and then it can be called by:
bttn_0["command"]();
so it will just run op1.num_press(0);.
If you wouldn't use lambda and do this:
bttn_0["command"] = op1.num_press(0);
"command" key would containt result of function call op1.num_press(0), not a new function.
For a quick example try run this:
class Test(): def fun(self, s): print "Hello %s!" % (s) testObj = Test();testObj.fun("world");buttonDict = {'command': None}buttonDict['command'] = lambda: testObj.fun("IcedEskimo");buttonDict['command']();

Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now