Can you change a Tkinter widget's master?

Fredrik Lundh fredrik at pythonware.com
Sat May 12 12:46:55 EDT 2001


Theodore D. Sternberg wrote:
> In Tkinter, is there any way to change a widget's master?  Assigning to
> the master attribute doesn't seem to have any effect.

nope.  widgets are bound to their parent (master) when they're
created.  assigning to the master attribute will only mess up the
internal structures...

> Setting (or resetting) the master would be the key to true compound widgets.
> For example, you could subclass Frame to take as constructor arguments several
> widgets (of any kind) and arrange them in some given way.

you can use template classes, which can be composed freely,
and which creates the real widgets on demand.  an example:

    dialog = Dialog(
        Label(text="enter your name"),
        Entry(width=20, name="name"),
        ButtonBox(
            Button(text="OK", command=self.ok),
            Button(text="Cancel", command=self.cancel)
            )
        )
    result = dialog.display()
    if result:
        print result.name

(this is from an unpublished corner of Tkinter 3000)

Cheers /F





More information about the Python-list mailing list