tkinter 访问按钮配置信息

tkinter access button config information

我正在编写一个代码,使我能够使用 GitHub 中的 phue 库来控制家中的色调灯。我使用 Tkinter 作为 GUI,我需要将每个房间分配给一个按钮和一个 "ON" 按钮。为此,我需要以某种方式访问​​分配给每个房间按钮的文本变量。我想象它会是这样的:

from tkinter import *
root = Tk()
button = Button(root, text = "room 1")
button.pack()
print(button.config(text)) #this should return "room 1"
root.mainloop()

非常感谢帮助。

简答:print(button['text'])

长答案: