我正在尝试查看我在程序中单击了哪个按钮,然后单独更新该按钮上的文本。如何找到点击的按钮?该程序是一个tictactoe游戏,我需要在我点击的位置放置一个X.代码如下:
#sets up the buttons
for i in range(1,10):
self.button = tk.Button(mainWindow, width=30, height=14, bg="white", text="",command=self.Click)
listOfButtons.append(self.button)
for button in listOfButtons:
"""
Grids each button dynamically with the specified row and column. each time through the loop it will
increase the column by 1 until it gets to 3. When columnNum == 4, it will reset it to 1 and add 1 to the
row.
"""
button.grid(row=rowNum, column=columnNum)
columnNum += 1
if(columnNum == 4):
rowNum += 1
columnNum = 1
def Click(self):
#Button command init
for button in listOfButtons: