Displaying text when a button is clicked in python
<p>Here i create a 9 buttons and when button is clicked hello must be displayed on the button....i know its simple but i'm not getting where did i get wrong.Thanks in advance.
Here's the code</p>

<pre><code>from Tkinter import *
class Design:
def __init__(self):
    self.button={}
    self.root=Tk()
    self.root.title("Simple Design")
    self.root.geometry("300x300")
    for i in range(3):
        for j in range(3):
            self.button[i,j]=Button(self.root,text="*",padx=12,pady=12).grid(row=i,column=j)

    self.click()



def click(self):
    for i in range(3):
        for j in range(3):
            handler=lambda i,j:self.update(i,j)
            print "click function"
            self.button[i,j]=Button(self.root,command=handler)

def update(self,i,j):
    self.button[i,j]=Button(self).grid()
    self.button[i,j]["text"]="Hello"
    print "Hello"
</code></pre>

<p>Right now i can't test the your code, but i see the problem here:
<code>self.button[i,j]=Button(self.root,text="*",padx=12,pady=12).grid(row=i,column=j)</code>! You are calling <code>.grid()</code>, which has no return. So your self.button[i,j] is <code>None</code>!</p>

<p>Just do it in 2 lines:
<code>self.button[i,j]=Button(self.root,text="*",padx=12,pady=12)</code> and <code>self.button[i,j].grid(row=i,column=j)</code></p>

python button tkinter