I am learning to use tkinter and I cannot figure out how to open a text file and save the data so that I can use the data in other calculations. In my code below a button is created that when pressed asks for and opens a file. It then prints the content of the file in the console. If the file contains for example a single number, say 100, I can't figure out how to save that number as a variable like "a."
from tkinter.filedialog import askopenfile
root = Tk()
root.geometry('200x100')
# This function will be used to open
# file in read mode and only Python files
# will be opened
def open_file():
file = askopenfile(parent=root, filetypes =[('Text Files', '*.txt')])
if file is not None:
content = file.read()
print(content)
a = content
btn = Button(root, text ='Open', command = lambda:open_file())
btn.pack(side = TOP, pady = 10)