IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
20.1.4 Mapping Basic Tk into Tkinter


20.1.4 Mapping Basic Tk into Tkinter

Class commands in Tk correspond to class constructors in 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.

    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. See section 20.1.6 on setting options.

    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.

    .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. See the Tix module documentation for additional information on the Form geometry manager.

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

See About this document... for information on suggesting changes.