Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有十八个按钮需要在按下另一个按钮时从一个图像变为另一个图像。我可以在每个上调用 .configure 并以这种方式进行设置,但是,我觉得好像有一种更简洁更简单的方法。有任何想法吗?
如果按钮都在列表中,您可以遍历它们,如下所示:
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)
你是这么想的吗?