0

我有十八个按钮需要在按下另一个按钮时从一个图像变为另一个图像。我可以在每个上调用 .configure 并以这种方式进行设置,但是,我觉得好像有一种更简洁更简单的方法。有任何想法吗?

4

1 回答 1

1

如果按钮都在列表中,您可以遍历它们,如下所示:

self.buttons = [button1, button2, ..., button18]

def updateButtonImage(self):
    for button in self.buttons:
        button.configure(image=self.newImage)

updateButton = Button(root, text="Change button image", command=self.updateButton)

你是这么想的吗?

于 2013-08-12T22:25:36.713 回答