1

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

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"
Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
  • 3
    Possible duplicate of [How to change Tkinter label text on button press](http://stackoverflow.com/questions/29828477/how-to-change-tkinter-label-text-on-button-press) – Harrison Sep 02 '16 at 02:11

1 Answers1

0

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

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

VRage
  • 1,458
  • 1
  • 15
  • 27