Pass a variable to a function via TK button

  button, python, tkinter

I have defined the following functions in a module called script.py

def load_file():
    file_name = filedialog.askopenfile(filetypes=['EXE files', '*.exe'])
    return file_name   

def simulation(input_path, input_par): # this works fine
    # the functionruns an EXE file ang gives me two lists lst1 and lst2
    return lst1, lst2 

Now the following button defined in the main.py calls the load_file function and it works fine (I print the path from within the function in the terminal). What I cannot igure out is how to pass the path I get within the load_file function as arrgument input_path to the function simulation via the button within the main.py. Pleas guys help me out here…I am stuck

var
button = Button(frame_file, text='Open file', command=load_file)
button.grid(row=1, column=1)

Source: Python Questions

LEAVE A COMMENT