簡體   English   中英

獲取 tkinter askopenfilenames() function 調用結果

[英]Get tkinter askopenfilenames() function call result

我想獲取本地磁盤上的文件名列表並使用 askopenfilenames() function ,我的腳本是:

from tkinter import *
from tkinter.filedialog import askopenfilenames

window = Tk()
window.title('File Viewer')
lb=Label(window, text='Select your files:')
lb.pack(side=LEFT, fill=BOTH)

def selectfiles():
    files = askopenfilenames(initialdir="D:\\Document", title="Select files")
    fileList = window.tk.splitlist(files)
    return fileList

btn = Button(window,text='Select Files',command=selectfiles)
btn.pack(side=RIGHT, fill=BOTH)
window.mainloop()

但是單擊“選擇文件”按鈕后如何使用文件名?

askopenfilenames返回文件名列表或如果選擇取消按鈕則返回空列表,以便您可以訪問代碼中變量files中的文件名。 這將是文件的完整路徑。 如果這是您所追求的,您可以進行一些拆分並僅獲取文件名

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM