我可以制作一个这样的 tkinter 按钮:
button1 = ttk.Button(root, text = "Button 1", command=lambda: button_click(button1))
或者像这样循环:
tk.Button(root, text=f"Button {i}", command=lambda x=i: button_click(x)).pack()
但是第二个按钮没有像 button1 那样的变量名。因此,我无法通过名称访问它:
def button_click(button):
button_text = button.cget('text')
ttk.Label(root, text = button_text).pack()
或者在这样的循环中创建时,第二个按钮实际上是否具有 tkinter 默认名称?