remember information for use on events--simply assign the information to self instance attributesclass someguiclassdef __init__(self)self self 'spambutton(text='hi'command=self handlerdef handler(self)use self xself because the event will be dispatched to this class' method with reference to the original instance objectself gives access to attributes that retain original data in effectthe instance' attributes retain state information to be used when events occur especially in larger guisthis is much more flexible technique than global variables or extra arguments added by lambdas callable class object callback handlers because python class instance objects can also be called if they inherit __call__ method to intercept the operationwe can pass one of these to serve as callback handler too example - shows class that provides the required function-like interface example - pp \gui\intro\gui py import sys from tkinter import class hellocallabledef __init__(self)self msg 'hello __call__ worlddef __call__(self)print(self msgsys exit(__init__ run on object creation __call__ run later when called class object looks like function widget button(nonetext='hello event world'command=hellocallable()widget pack(widget mainloop(herethe hellocallable instance registered with command can be called like normal functionpython invokes its __call__ method to handle the call operation made in tkinter on the button press in effectthe general __call__ method replaces specific bound method in this case notice how self msg is used to retain information for use on events hereself is the original instance when the special __call__ method is automatically invoked all four gui variants create the same sort of gui window (figure - )but print different messages to stdout when their button is pressed graphical user interfaces