我正在使用OS X.我双击我的脚本从Finder运行它.此脚本导入并运行以下函数.
我希望脚本能够显示一个Tkinter打开文件对话框并返回所选文件列表.
这是我到目前为止所拥有的:
def open_files(starting_dir):
"""Returns list of filenames+paths given starting dir"""
import Tkinter
import tkFileDialog
root = Tkinter.Tk()
root.withdraw() # Hide root window
filenames = tkFileDialog.askopenfilenames(parent=root,initialdir=starting_dir)
return list(filenames)
Run Code Online (Sandbox Code Playgroud)
我双击脚本,终端打开,打开Tkinter文件对话框. 问题是文件对话框在终端后面.
有没有办法抑制终端或确保文件对话框最终?
谢谢,韦斯
我正在用Python做一个小项目,我想浏览一个文件或目录来获取它们的路径.
我正在使用Tkinter,我只能找到一个文件浏览器:
filename = tkFileDialog.askopenfilename(parent=root,title='Open file to encrypt')
Run Code Online (Sandbox Code Playgroud)
或只是一个目录浏览器:
dir = tkFileDialog.askdirectory(parent=root, title='Open file to encrypt')
Run Code Online (Sandbox Code Playgroud)
是否有可能将这两者结合起来?谢谢你的所有答案!