I'm trying to import a file from a tkinter GUI to be used in the rest of my code.
import numpy as np
import tkinter as tk
from tkinter import filedialog
def FileImport():
file = filedialog.askopenfilename()
label = tk.Label(root, text = "Selected: "+file).pack()
root= tk.Tk()
root.title('Main')
label = tk.Label(root, text = "Upload a file: ", fg="purple").pack()
button = tk.Button(root, text='Upload',fg="blue", command=FileImport)
button.pack()
root.mainloop()
uploaded_file = np.fromfile(file)
Then I'm trying to perform calculation and other things on that file data.
The issue is that when I run the code the GUI works "fine", I am able to upload a file but then it tells me that name 'uploaded_file' is not defined. I think I'm missing some connection between my GUI and the rest of my code? Any advice?