Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Simple file dialog

  • filedialog
  • askopenfilename

This is another way of using the Tk widgets. Here we have a plain command-line script, but instead of using the standard input() function of Python to ask for a filename it launches a Tk File-dialog widget to allow the user to browse and select a file.

from tkinter import filedialog

input_file_path = filedialog.askopenfilename(filetypes=(("Excel files", "*.xlsx"), ("CSV files", "*.csv"), ("Any file", "*")))
print(input_file_path)

input("Press ENTER to end the script...")