Python Tkinter按钮对应输入框的设置值

Python Tkinter按钮对应输入框的设置值,python,tkinter,Python,Tkinter,我在这件事上纠缠了一段时间。我基本上是在尝试制作一个允许我加载多个文件的应用程序。目前,该应用程序有6个浏览按钮,旁边是相应的输入框。我试图让浏览按钮将文件位置字符串发送到它旁边的输入框。不幸的是,目前它只在底部输入框中添加文件名字符串。如何将其输出到相应行的框中 希望这个解决方案也能帮助我理解当我按下execute时如何返回正确的值 到目前为止,我所掌握的情况如下 提前谢谢 r=3 for i in range(6): #CREATE A TEXTBOX

我在这件事上纠缠了一段时间。我基本上是在尝试制作一个允许我加载多个文件的应用程序。目前,该应用程序有6个浏览按钮,旁边是相应的输入框。我试图让浏览按钮将文件位置字符串发送到它旁边的输入框。不幸的是,目前它只在底部输入框中添加文件名字符串。如何将其输出到相应行的框中

希望这个解决方案也能帮助我理解当我按下execute时如何返回正确的值

到目前为止,我所掌握的情况如下

提前谢谢

    r=3
    for i in range(6):
        #CREATE A TEXTBOX
        self.filelocation = Entry(self.master)
        self.filelocation["width"] = 60
        self.filelocation.focus_set()
        self.filelocation.grid(row=r,column=1)

        #CREATE A BUTTON WITH "ASK TO OPEN A FILE"
        self.open_file = Button(self.master, text="Browse...", command=lambda i=i: self.browse_file(i))
        self.open_file.grid(row=r, column=0) #put it beside the filelocation textbox

        #CREATE A TEXT ENTRY FOR HELICOPTER ROUTE NAME
        self.heliday = Entry(self.master)
        self.heliday["width"] = 20
        self.heliday.grid(row=r,column=2)
        r = r+1

    #now for a button
    self.submit = Button(self.master, text="Execute!", command=self.start_processing, fg="red")
    self.submit.grid(row=r+1, column=0)

def start_processing(self):
    #more code here
    print "processing"

def browse_file(self, i):
    #put the result in self.filename
    self.filename = tkFileDialog.askopenfilename(title="Open a file...")

    #this will set the text of the self.filelocation
    self.filelocation.insert(0,self.filename)

您必须保留对所有输入框的引用。为此,您可以将条目创建更改为:

self.filelocation = []
for i in range(6):
    #CREATE A TEXTBOX
    self.filelocation.append(Entry(self.master))
    self.filelocation[i]["width"] = 60
    self.filelocation[i].focus_set()
    self.filelocation[i].grid(row=r,column=1)
这样,您可以保留对列表中所有输入框的引用。然后,您可以使用以下方法确保文件名输入正确:

self.filelocation[i].insert(0,self.filename)