美文网首页
【学习笔记】Python-利用文件对话框获取文件路径或文件夹路径

【学习笔记】Python-利用文件对话框获取文件路径或文件夹路径

作者: WJ96 | 来源:发表于2019-04-05 22:17 被阅读0次

解决方案

回答最多的就是使用python内部集成的tkinter图形库

Python3

import tkinter as tk
from tkinter import filedialog
 
root = tk.Tk()
root.withdraw()
 
file_path = filedialog.askopenfilename()

Python2

import Tkinter, tkFileDialog
 
root = Tkinter.Tk()
root.withdraw()
 
file_path = tkFileDialog.askopenfilename()

常见的文件选择对话框函数有

打开一个文件:askopenfilename()
打开一组文件:askopenfilenames()
保存文件:asksaveasfilename()
选择文件夹:askdirectory()

参考来源:

python文件选择对话框
python一句话之利用文件对话框获取文件路径

相关文章

网友评论

      本文标题:【学习笔记】Python-利用文件对话框获取文件路径或文件夹路径

      本文链接:https://www.haomeiwen.com/subject/xwzkiqtx.html