I would like to feed two entries in my GUI with file paths to 2 different files. Every entry has his own BROWSE BUTTON. I would like to use for it one function called browse_for_file. However, I have got a problem that running this script, buttons are pressed automatically and thus 'Select A File' windows poup up immediately just after running the script. What am I doing wrong ? How to use one fucntion for feeding two entries? Below is my code:
from tkinter import *
from tkinter import filedialog
root = Tk()
def browse_for_file(entry):
file_path = filedialog.askopenfilename(initialdir = "/C:", title = "Select A File", filetypes = [("zip files", "*.zip")])
entry.insert (0, filepath)
file_path1=StringVar()
e1 = Entry(root, width = 75, textvariable = file_path1)
e1.pack()
button1 = Button(root, text="Browse", command = browse_for_file(e1))
button1.pack()
folder_path2=StringVar()
e2 = Entry(root, width = 75, textvariable = folder_path2)
e2.pack()
button2 = Button(root, text="Browse", command = browse_for_file(e2))
button2.pack()
root.mainloop()