[Tutor] Update a button content on click

Alan Gauld alan.gauld at btinternet.com
Tue Feb 15 13:28:47 CET 2011


"ANKUR AGGARWAL" <coolankur2006 at gmail.com> wrote

> I am looking for a method using Tkinter module to update the button 
> on the
> click.

Define an event handler command for the button.
Lets call it sayHi()

def sayHi(self):
     self.myButton['text'] = 'hi'
     # Note:event handlers don't return results so store it as an 
attribute
     self.myButtonResult = 'hi'

Now create the widget with spam as the handler.

self.myButton = Button(parent, text='hello', command = spam)

That's it.

> the its click should be "hi". I tried it through event handling but 
> failed
> to do so.

It would be more helpful if you posted the code that you tried
and a more detailed explanation of "failed to do so".
What happened? Did it update but not store a value?
Did you get an error message? Did anything happen?

The more specific information you provide the more likely you
are to get a specific solution that works.

HTH,


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/




More information about the Tutor mailing list