scopes explicitlyusing either of these two techniquesuse simple defaults func (lambda self=selfname=keyself printit(name)use bound method default func (lambda handler=self printitname=keyhandler(name)todaywe can get away with the simpler enclosing -scope reference technique for selfthough we still need default for the key loop variable (and you may still see the default forms in older python codenote that the parentheses around the lambdas are not required herei add them as personal style preference just to set the lambda off from its surrounding code (your mileage may varyalso notice that the lambda does the same work as nested def statement herein practicethoughthe lambda could appear within the call to button itself because it is an expression and it need not be assigned to name the following two forms are equivalentfor (keyvaluein demos items()func (lambda key=keyself printit(key)can be nested button(for (keyvaluein demos items()def func(key=key)self printit(keybut def statement cannot you can also use callable class object here that retains state as instance attributes (see the tutorial' __call__ example in for hintsbut as rule of thumbif you want lambda' result to use any names from the enclosing scope when later calledeither simply name them and let python save their values for future useor pass them in with defaults to save the values they have at lambda function creation time the latter scheme is required only if the variable used may change before the callback occurs when runthis script creates the same window (figure - but also prints dialog return values to standard outputhere is the output after clicking all the demo buttons in the main window and picking both cancel/no and then ok/yes buttons in each dialogc:\pp \gui\tourpython demodlg-print py color returns =(nonenonecolor returns =(( )'# ff'query returns =no query returns =yes input returns =none input returns = open returns =open returns = :/users/mark/stuff/books/ /pp /dev/examples/pp /launcher py error returns =ok now that 've shown you these dialog resultsi want to next show you how one of them can actually be useful tkinter tourpart