当前位置:   article > 正文

Python 文件选择框askopenfilename的参数_askopenfile()参数

askopenfile()参数

需求:打开一个文件选择框(单选.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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
from tkinter.filedialog import askopenfilename
file_path=askopenfilename(title='Select the diagnostic instrument .exe file', filetypes=[('EXE', '*.exe'), ('All Files', '*')],initialdir='C:\\Windows')
  • 1
  • 2

在这里插入图片描述

但是会多出一个主界面
在这里插入图片描述

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

函数返回值为绝对路径

在这里插入图片描述

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/499230
推荐阅读
相关标签
  

闽ICP备14008679号