lambda here entirelywe could register the handler itself and cut out the middleman although simple in this trivial examplearguments are generally preferred to globalsbecause they make external dependencies more explicitand so make code easier to understand and change in factthe same handler might be usable in other contextsif we don' couple it to global variablesvalues while you'll have to take it on faith until we step up to larger examples with more complex state retention needsavoiding globals in callbacks and guis in general both makes them more reusableand supports the notion of multiple instances in the same program it' good programming practicegui or not passing in enclosing scope values with default arguments more subtlynotice that if the button in this example was constructed inside function rather than at the top level of the filename would no longer be global but would be in the enclosing function' local scopeit seems as if it would disappear after the function exits and before the callback event occurs and runs the lambda' codedef handler(ab)use and def makegui() button(text='ni'command=(lambdahandler( 'spam'))makegui(mainloop(remembers makegui' scope is gone by this point luckilypython' enclosing scope reference model means that the value of in the local scope enclosing the lambda function is automatically retainedfor use later when the button press occurs this usually works as we want todayand automatically handles variable references in this role to make such enclosing scope usage explicitthoughdefault argument values can also be used to remember the values of variables in the enclosing local scopeeven after the enclosing function returns in the following codefor instancethe default argument name (on the left side of the = defaultwill remember object because the variable name (on the right side of the =xis evaluated in the enclosing scopeand the generated function is later called without any argumentsdef handler(ab)use and older pythonsdefaults save state def makegui() button(text='ni'command=(lambda =xhandler( 'spam'))since default arguments are evaluated and saved when the lambda runs (not when the function it creates is later called)they are way to explicitly remember objects that graphical user interfaces