change text of a Tkinter Button by clicking it

Peter Otten __peter__ at web.de
Thu Sep 29 02:27:00 EDT 2011


Sean McIlroy wrote:

> hello
> 
> (how) can you change the text of a Tkinter Button by clicking it?
> something like
> 
> def click(index): return lambda: buttons[index].text = 'hello'
> buttons = [Button(root,command=click(index)) for index in
> range(numbuttons)]
> 
> only with an attribute that Buttons actually have. sorry to have to
> ask such a see-spot-run question. thanks if you can help.

See http://infohost.nmt.edu/tcc/help/pubs/tkinter/universal.html

You can set the text of a Button widget with

button["text"] = ...

or

button.configure(text=...)






More information about the Python-list mailing list