There's more...

The tkinter.filedialog module includes some variations of these functions that allow you to directly retrieve the file objects.

For instance, askopenfile returns the file object corresponding to the selected file, instead of having to call open with the path returned by askopenfilename. We still have to check whether the dialog has not been dismissed before calling the file methods:

import tkinter.filedialog as fd

filetypes = (("Plain text files", "*.txt"),)
my_file = fd.askopenfile(title="Open file", filetypes=filetypes)
if my_file:
print(my_file.readlines())
my_file.close()
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset