[Tkinter-discuss] Changing the label of a tix.NoteBook tab

Michael Lange klappnase at web.de
Sat Apr 25 16:54:21 CEST 2009

On Sat, 25 Apr 2009 23:31:00 +0930
Luke Maurits <luke at maurits.id.au> wrote:

> Hallo Michael,
> <snip>
> > obviously the pageconfigure() method is missing from Tix.py, so this is perfectly what you
> > are suposed to do :)
> > If you wish you can do the same a bit shorter:
> > 
> >   nb.tk.call(nb._w,"pageconfigure","tab", "-label", "Bar")
> Thank you for your very prompt reply.  I am surprised that this is the only way to do what I want but am glad that I have stumbled upon the correct way.  I will certainly use your shorter/neater version in my application since it is much easier to read.
> I wonder why the decision was made not to implement pageconfigure in Tix.py?  It seems like this would be very easy:
> def pageconfigure(self, name, cnf={}, **kw):
>         self.tk.call(self._w, "pageconfigure", name, *self._options(cnf, kw))
> should do it perfectly, no?  This would certainly be much more user friendly, I think a lot of people would give up before discovering how to call it through tk.call.  Still, I don't suppose anybody on this list is likely to actually know what the author of Tix.py was thinking at the time, so it's not really something to be discussed here.

Things are a little more complicated though; if you only pass the page name to pageconfigure, without any option,
you want all options with their current values to be returned, if you pass one option without
value the current value should be returned, as in Tkinter.Widget.configure().
The Tix way to achieve this seems to be (taken from Tix.PanedWindow.paneconfigure()):

    def pageconfigure(self, page, cnf={}, **kw):
        if cnf is None:
            return _lst2dict(
                self.tk.call(self._w, 'pageconfigure', page._name)))
        self.tk.call(self._w, 'pageconfigure', page._name, *self._options(cnf, kw))

which appears to be broken, though; when I pass only a pagename to it I get None as return value,
I need to call nb.pageconfigure(pagename, None) to get something returned, which is at least
unintuitive, and passing an option as in nb.pageconfigure(pagename, 'label') causes an error.

A better way to implement it might be the typical Tkinter way:

    def pageconfigure(self, page, cnf={}, **kw):
        return self._configure(('pageconfigure', page._name), cnf, kw)

This allows at least partially to query current values, nb.pageconfigure(pagename, 'label')
returns a tuple ('label', '', '', '', 'foobar'), nb.pageconfigure(pagename) still returns None if
used without None as second argument.


More information about the Tkinter-discuss mailing list