Python 文件选择框askopenfilename的参数

需求:打开一个文件选择框(单选.exe)

askopenfilename的参数,返回值为选择文件的绝对路径
from tkinter.filedialog import askopenfilename
# For the following classes and modules:
# options (all have default values):
# - defaultextension: added to filename if not explicitly given
# - filetypes: sequence of (label, pattern) tuples.  the same pattern may occur with several patterns.  use "*" as pattern to indicate all files.
# - initialdir: initial directory.  preserved by dialog instance.
# - initialfile: initial file (ignored by the open dialog).  preserved by dialog instance.
# - parent: which window to place the dialog on top of
# - title: dialog title
# - multiple: if true user may select more than one file
# options for the directory chooser:
# - initialdir, parent, title: see above
# - mustexist: if true, user must pick an existing directory
from tkinter.filedialog import askopenfilename
file_path=askopenfilename(title='Select the diagnostic instrument .exe file', filetypes=[('EXE', '*.exe'), ('All Files', '*')],initialdir='C:\\Windows')

Python 文件选择框askopenfilename的参数_第1张图片

但是会多出一个主界面
Python 文件选择框askopenfilename的参数_第2张图片

如果你原先有个界面,这个空白界面就不会出现了。

函数返回值为绝对路径

在这里插入图片描述

你可能感兴趣的:(python3)