Newbie
Newbie

Reputation: 11

Python-Tkinter-askopenfilename: Use filepath of the opened file for reading values

I want to store the filepath to an opened file (via askopenfilename in tkinter) into a variable and later on use it for other purposes such as reading the file through the variable and use its values. How do I do that?

Also I am an absolute beginner so please explain the procedure too. Thanks in advance.

Upvotes: 0

Views: 247

Answers (1)

C-Sharpsz
C-Sharpsz

Reputation: 45

Here is a code to start you off

from tkinter import filedialog as fd


filename = fd.askopenfilename(title = "Attach file", initialdir = 'c:/')


f = open(filename, "r")
print(f.read())
f.close()

Upvotes: 1

Related Questions