Python tkinter,获取用户输入以指定要更新的标签

Python tkinter,获取用户输入以指定要更新的标签,python,tkinter,user-input,tkinter-entry,Python,Tkinter,User Input,Tkinter Entry,我有46个标签配置了一个图像。我希望用户在条目小部件中输入要更改的标签,然后我希望更改标签图像。这是我的一小部分。此代码将触发AttributeError:“str”对象没有属性“configure” class Agilent(tk.Frame): def __init__(self, master, **kw): super().__init__(master, **kw) self.master = master # Cell Update label plus

我有46个标签配置了一个图像。我希望用户在条目小部件中输入要更改的标签,然后我希望更改标签图像。这是我的一小部分。此代码将触发AttributeError:“str”对象没有属性“configure”

class Agilent(tk.Frame):

def __init__(self, master, **kw):
    super().__init__(master, **kw)
    self.master = master

    # Cell Update label plus text
    self.cell_update = tk.Label(self.master, text="Select Cell", font=('times', 14, 'bold'))
    self.cell_update.place(x=200, y=200)
    self.cell_update_entry = tk.Entry(self.master, font=('times', 14, 'bold'), width=32)
    self.cell_update_entry.place(x=400, y=200)

    # Takes a value
    self.brick = tk.Label(self.master, text="Brick Number", font=('times', 14, 'bold'))
    self.brick.place(x=460, y=600)
    self.brick_entry = tk.Entry(self.master, font=('times', 14, 'bold'), width=4)
    self.brick_entry.place(x=760, y=600)
    self.brick_entry.config(bd=4)

    # execute button
    self.change_cell_button = tk.Button(self.master, text="Change Cell", command=self.cell_color)
    self.change_cell.place(x=800, y=300)

    self.grey_cell = ImageTk.PhotoImage(Image.open(file))
    self.grey_cell_image = self.grey_cell

    self.orange_cell = ImageTk.PhotoImage(Image.open(file))       
    self.orange_cell_image = self.orange_cell

    self.red_cell = ImageTk.PhotoImage(Image.open(file))  
    self.red_cell_image = self.red_cell

    self.green_cell = ImageTk.PhotoImage(Image.open(file))            
    self.green_cell_image = self.green_cell

    # This is 1 of 46 options labeled cell_1.....cell_n
    self.cell_1 = tk.Label(self.master, image=self.grey_cell_image, background='white')
    self.cell_1.place(x=1460, y=20)


def cell_color(self):
    r = self.cell_update_entry.get()
    x = "self." + r                     # Build string to use as Label call
    y = int(self.brick_entry.get())

    if y < 1:
        self.cell_1.configure(image=self.orange_cell) # If I call the cell directly this works

    elif y % 2 == 0:
        x.configure(image=self.green_cell)#AttrinuteError: 'str' object has no attribute 'configure'

    else:
        x.configure(image=self.red_cell)#AttrinuteError: 'str' object has no attribute 'configure'

if __name__ == "__main__":

    root = tk.Tk()
    root.title("Wirebond Voltage Drop")
    root.geometry('1600x1200')
    root.resizable(False, False)

    dmm = Agilent(root)
    root.mainloop()

如何从您的产品中识别特定的tk.标签?更改为将标签放入自己的self.board=tk.Frameself.master。。正在做tk.Labelself.board。。。并使用感谢stovfl。每个标签名称标识为单元格n,n为数字1-46。我遗漏了其他一些内置逻辑,它们定义了每个单元的去向。使用self.board会对我的问题有帮助吗?我的错,应该是:x=getattrself,cell_uu+r标准规则:如果有许多元素,那么应该将它们保留在列表或字典中,而不是单独的变量中。而且你没有问题得到它-即self.all_cells[r]。您可以使用for循环处理列表中的所有元素,这样代码就更短了。如何从列表中识别特定的tk.标签?更改为将标签放入自己的self.board=tk.Frameself.master。。正在做tk.Labelself.board。。。并使用感谢stovfl。每个标签名称标识为单元格n,n为数字1-46。我遗漏了其他一些内置逻辑,它们定义了每个单元的去向。使用self.board会对我的问题有帮助吗?我的错,应该是:x=getattrself,cell_uu+r标准规则:如果有许多元素,那么应该将它们保留在列表或字典中,而不是单独的变量中。而且你没有问题得到它-即self.all_cells[r]。您可以使用for循环处理列表中的所有元素,这样代码就更短了。