tkFileDialog
不具备的功能remeber所选文件的顺序,这样你可以建立自己的FileDialog
或...
...建立一些对话框,选择文件的顺序从tkFileDialog
拿到文件后,
import Tkinter as tk
import tkFileDialog
def Selector(data):
def append(widget, element, results, display):
# append element to list
results.append(element)
# disable button
widget['state'] = 'disabled'
# add element to label
current = display['text']
if current:
current += '\n'
display['text'] = current + element
# create window
root = tk.Tk()
# list for correct order
results = []
# label to display order
tk.Label(root, text='ORDER').pack()
l = tk.Label(root, anchor='w', justify='left')
l.pack(fill='x')
# buttons to select elements
tk.Label(root, text='SELECT').pack()
for d in data:
b = tk.Button(root, text=d, anchor='w')
b['command'] = lambda w=b, e=d, r=results, d=l:append(w, e, r, d)
b.pack(fill='x')
# button to close window
b = tk.Button(root, text='Close', command=root.destroy)
b.pack(fill='x', pady=(15,0))
# start mainloop
root.mainloop()
return results
# --- main ---
root = tk.Tk()
filez = tkFileDialog.askopenfilenames(parent=root,title='Choose a file')
root.destroy()
print(filez)
filez = Selector(filez)
print(filez)
你将不得不建立自己的'tkFileDialog'来记住顺序。或者创建对话框,让你改变列表上的元素顺序(从'tkFileDialog'获得所有文件后)。 – furas