赞
踩
需求:打开一个文件选择框(单选.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')
但是会多出一个主界面
如果你原先有个界面,这个空白界面就不会出现了。
函数返回值为绝对路径
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。