here create 9 buttons , when button clicked hello must displayed on button....i know simple i'm not getting did wrong.thanks in advance. here's code
from tkinter import * class design: def __init__(self): self.button={} self.root=tk() self.root.title("simple design") self.root.geometry("300x300") in range(3): 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): in range(3): 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"
right can't test code, see problem here: self.button[i,j]=button(self.root,text="*",padx=12,pady=12).grid(row=i,column=j)
! calling .grid()
, has no return. self.button[i,j] none
!
just in 2 lines: self.button[i,j]=button(self.root,text="*",padx=12,pady=12)
, self.button[i,j].grid(row=i,column=j)
Comments
Post a Comment