여기에 9 개의 버튼을 만들고 버튼을 클릭하면 hello가 버튼에 표시되어야합니다 .... 그 단순함을 알고 있지만 어디서 잘못되었는지 알 수 없습니다. 미리 감사드립니다. 다음은 코드 지금버튼을 클릭하면 파이썬에서 텍스트가 표시됩니다
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"
가능한 복제 (http://stackoverflow.com/questions/29828477/how-to-change [버튼 프레스에 Tkinter의 레이블 텍스트를 변경하는 방법] -tkinter-label-text-on-button-press) – Harrison