try:
# Python 2
from Tkinter import Tk
from tkFileDialog import askopenfilename
except ImportError:
# Python 3
from tkinter import Tk
from tkinter.filedialog import askopenfilename
def get_file_dialog(title, initial_dir, filetypes):
"""
title is the text to show in the title bar of the dialog
initial_dir is the directory to show when opening the dialog
filetypes is a list/tuple like this:
(('All Files', '.*'), ('MP3', '.mp3'), ('WAV', '.wav'))
"""
tk_temp = Tk()
tk_temp.withdraw() # Returns a value we don't need
filepath = askopenfilename(filetypes=filetypes,
initialdir=initial_dir,
title=title)
if filepath is ():
filepath = ''
return filepath
假设您的意思是对于桌面应用程序,您可能需要
askopenfilename
。这里有一个简单的包装。你知道吗相关问题 更多 >
编程相关推荐