Backwards Compatibility

Keyword arguments were introduced in Python 1.3. Before that, options were passed to the widget constructors and configure methods using ordinary Python dictionaries. The source code could then look something like this:

    self.button = Button(frame, {"text": "QUIT", "fg": "red", "command": frame.quit})
    self.button.pack({"side": LEFT})

The keyword argument syntax is of course much more elegant, and less error prone. However, for compatibility with existing code, Tkinter still supports the older syntax. You shouldn't use this syntax in new programs, even if it might be tempting in some cases. For example, if you create a custom widget which needs to pass configuration options along to its parent class, you may come up with something like:

    def __init__(self, master, **kw):
        Canvas.__init__(self, master, kw) # kw is a dictionary

This works just fine with the current version of Tkinter, but it may not work with future versions. A more general approach is to use the apply function:

    def __init__(self, master, **kw):
        apply(Canvas.__init__, (self, master), kw)

The apply function takes a function (an unbound method, in this case), a tuple with arguments (which must include self since we're calling an unbound method), and optionally, a dictionary which provides the keyword arguments.