[ Next: Relationship | Previous: BriefTclTk | Contents ]

Mapping Basic Tk into Tkinter

Class commands in Tk correspond to class constructors in Tkinter.
    Tk					Tkinter

    button .fred		=====>	fred = Button()
The master of an object is implicit in the new name given to it at creation time. In Tkinter, masters are specified explicitly.

    Tk					Tkinter

    button .panel.fred		=====>	fred = Button(panel)
The configuration options in Tk are given in lists of hyphened tags followed by values. In Tkinter, options are specified as keyword-arguments in the instance constructor, and keyword-args for configure calls or as instance indices, in dictionary style, for established instances. (Before Python 1.3, which introduced keyword arguments, dictionaries were passed to specify constructor option/value pairs.) See the section on setting options.
    Tk					Tkinter

    button .fred -fg red	=====>	fred = Button(panel, fg = "red")
    .fred configure -fg red	=====>	fred["fg"] = red
				OR ==>	fred.config(fg = "red")
In Tk, to perform an action on a widget, use the widget name as a command, and follow it with an action name, possibly with arguments (options). In Tkinter, you call methods on the class instance to invoke actions on the widget. The actions (methods) that a given widget can perform are listed in the Tkinter.py module.
    Tk					Tkinter

    .fred invoke		=====>	fred.invoke()
To give a widget to the packer (geometry manager), you call pack with optional arguments. In Tkinter, the Pack class holds all this functionality, and the various forms of the pack command are implemented as methods. All widgets in Tkinter are subclassed from the Packer, and so inherit all the packing methods.
    Tk					Tkinter

    pack .fred -side left	=====>	fred.pack(side = "left")