我写一个程序有很多按钮(100),并且每一个都需要一个唯一的结果,但所有的结果都差不多,这是第一个按钮的代码创建众多独特的事件
box1= 'filepath to text file'
def openfile(filename):
filetxt = (open(filename,"r").read())
return filetxt
var.set(filetxt)
def Box1():
var.set(openfile(box1))
openfile(box1)
window1 = Tk()
window1.geometry('450x450')
var = StringVar()
Button1 = Button(donut,text = "Box #1", command= Box1)
Button1.pack()
每个按钮都会做同样的事情,但访问一个不同的文件,是否有更有效的方法来做到这一点,而不是简单地为每个按钮编写一个唯一的回调函数?
非常感谢!你是对的,我不明白lambda感谢解释 –