我現在有這個tkintr應用程序將允許你上傳文件或多個文件中的Tkinter Python中上傳的文件數量。我希望能夠在控制檯上打印選擇多少個文件。我怎樣才能得到
目前我只能打印什麼選擇的文件與print self.uploadedfilenames
我試圖做len(self.uploadedfilenames)
但我得到了一些52一個文件,我不明白這是什麼
#!/usr/bin/env python
from Tkinter import *
import tkFileDialog
import tkMessageBox
class Application(object):
def __init__(self, master):
frame = Frame(master)
frame.pack()
self.file_opt = options = {}
options['defaultextension'] = '.txt'
options['filetypes'] = [('all files', '.*'), ('text files', '.txt')]
options['initialdir'] = 'C:\\'
options['initialfile'] = 'myfile.txt'
options['parent'] = master
options['title'] = 'This is a title'
#UPLOAD SECTION
Label(frame, text='Upload: ').grid(row=1, column=1)
self.upload = Button(frame, text = "Browse", command = self.askopenfile, width = 10).grid(row=1, column=2)
def askopenfile(self):
self.uploadedfilenames = tkFileDialog.askopenfilenames(multiple=True)
if self.uploadedfilenames == '':
tkMessageBox.showinfo(message="No file was selected")
return
else:
print len(self.uploadedfilenames)
root = Tk()
root.title('application')
_ = Application(root)
root.mainloop()
有沒有辦法找出有多少文件?
對我來說,它完美的作品,你會想到使用'len'。你確定你沒有做一些奇怪的事嗎? – nbro
它給了我一個數字,例如(54,71等)。然而,是不是文件中選擇@Axl –
請數量,展示我們到底使用的是做到這一點的代碼,因爲這不是你正在使用的代碼。 – nbro