I'm new in python and what I'm trying to do is reading an excel file, but I'm stuck due to that I don't want to read the file as soon as I open it, I wan't to press a button to read the file and do what I have to.
When I press "Calcular", I wan't to read the file, but right now I'm trying to print the path in a label with that button, to make sure my button is getting the path in the Entry.
Right now it prints the path in the label without pressing the button "Calcular", how can I pass the entry value as an argument? "lbl2" is where I wan't to print the Entry value (txtfld) using the button "Calcular".
from tkinter import *
from tkinter.filedialog import askopenfilename
def import_csv_data():
global v
csv_file_path = askopenfilename()
File = open(csv_file_path)
v.set(csv_file_path)
def calcular(ruta):
global v2
v2.set(ruta)
window=Tk()
window.title('Calcular Media') #Titulo
v = StringVar()
v2 = StringVar()
v2 = v
lbl = Label(window, text="Ruta", width=10, height=1).grid(row=0, column=0)
txtfld = Entry(window, textvariable=v).grid(row=0, column=1)
btn = Button(window, text="Calcular", command=calcular(v.get())).grid(row=0, column=2)
btn2 = Button(window, text="Buscar archivo", command=import_csv_data).grid(row=1, column=0)
lbl2 = Label(window, textvariable=v2).grid(row=5, column=0)
window.geometry("400x300")
window.mainloop()