simple: modifying label text elp?

Alex Martelli aleax at aleax.it
Fri Mar 21 02:20:40 EST 2003


vector wrote:

> this should be easy for all you pythonettes.
> i cant modify my label text.
> 
> i have an entry widget and simply saying
> w.insert(0,"new text")
> works like a treat
> ie i have set up textvariable etc when making the entry.
> i used eactly the same setupcode but with label
> and it dosnet work
> first of all,error- no insert on label widgets. allowed

Right -- labels don't support an insert method, which is special
to entry and text widgets only.  To set a label widget's text,
just as to set the text on most other widgets, you can use any
way to set the configuration option named 'text' of the widget:
most typical and useful,

    w.config(text='new text')

BTW, to get a configuration option of a widget, for example its
text, w.cget('text') is typical and useful.

> i read the guff and i think im supposed to use
> w.setvar(name='myvar',value='new text')
> no errors report but the label text dont change either:(

This call set the TCL variable named 'myvar' to the new value
and does not affect widget w.

Perhaps what you want to do is, rather:

    s = Tkinter.StringVar()
    w.config(textvariable=s)

and then

    s.set('new text')

will indeed affect the text displayed on the label.


Alex





More information about the Python-list mailing list