change text of a Tkinter Button by clicking it

S

Sean McIlroy

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.

peace
stm
 
P

Peter Otten

Sean said:
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=...)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top