如何使用Setter函数检查函数参数是否已更改-Python

如何使用Setter函数检查函数参数是否已更改-Python,python,python-3.x,python-2.7,tkinter,parameter-passing,Python,Python 3.x,Python 2.7,Tkinter,Parameter Passing,这是我的密码: def DisplayFiles(which): contentLabel = tk.Label(window, text = '\n'.join(files[indexlist[which]][1:])) contentLabel.place(x = 150, y = 80) 我正在使用Tkinter,当按下一个按钮时,我正试图用上述功能显示文件。变量“which”是按钮的字符串名称。“indexlist”是一个保存按钮名称索引的字典(我动态创建了它们)。我的

这是我的密码:

def DisplayFiles(which):
    contentLabel = tk.Label(window, text = '\n'.join(files[indexlist[which]][1:]))
    contentLabel.place(x = 150, y = 80)
我正在使用Tkinter,当按下一个按钮时,我正试图用上述功能显示文件。变量“which”是按钮的字符串名称。“indexlist”是一个保存按钮名称索引的字典(我动态创建了它们)。我的问题是试图显示两个不同按钮的文件。当我单击一个按钮时,上面的函数将显示文件。但当我单击另一个按钮时,标签显示在上一个按钮的上方。我正在研究destroy()方法,但我需要知道如何检查参数“which”何时更改。谢谢你的帮助


此外,indexlist和files的值也不是问题。我只是想找到一种方法来检查函数参数何时更改。谢谢

不要每次都制作新标签,只需更新旧标签即可

# make an empty Label
contentLabel = tk.Label(window)
contentLabel.place(x = 150, y = 80)

def DisplayFiles(which):
    # update the Label contents
    contentLabel.config(text = '\n'.join(files[indexlist[which]][1:]))

请说一句,我还没想到呢。谢谢