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