在unix平台上使用python 3.3。我已经看到许多示例,其中以下代码可以工作,但我遇到了问题。当我选择多个文件时,会出现一个错误消息对话框:"File /python/input_files/file1.txt file2.txt" does not exist
。这个错误是有意义的(尝试打开多个文件的字符串)但不明白为什么别人看不到它以及我该如何纠正它。通过按钮选择调用selectFiles
。感谢任何帮助。
from tkinter import *
from tkinter import ttk
from tkinter.filedialog import askopenfilenames
def selectFiles(self):
files = askopenfilenames(filetypes=(('Text files', '*.txt'),
('All files', '*.*')),
title='Select Input File'
)
fileList = root.tk.splitlist(files)
print('Files = ', fileList)
以下是完整的代码:
#!/usr/local/bin/python3.3
from tkinter import *
from tkinter import ttk
from tkinter.filedialog import askopenfilenames
class multifilesApp(Frame):
def __init__(self,master=None):
Frame.__init__(self,master)
def initializeUI(self):
self.master.title('Select Files Application')
self.grid(row=0, column=0,sticky=W)
# Create the button to select files
self.button1 = Button(self.master, text='Select Files', command=self.selectFiles, width=10)
self.button1.grid(row=30, column=0)
def selectFiles(self):
files = askopenfilenames(filetypes=(('Text files', '*.txt'),
('All files', '*.*')),
title='Select Input File'
)
InputFileList = root.tk.splitlist(files)
print('Files = ', InputFileList)
# Begin Main
if __name__ == "__main__":
root = Tk()
root.minsize(width=250, height=400)
root.geometry("1200x800")
# Call the parser GUI application
app = multifilesApp(master=root)
app.initializeUI()
app.mainloop()
答案 0 :(得分:0)
也许Sun4u上的Tcl / Tk存在问题
尝试在Tcl / Tk(example.tcl)
中运行示例package require Tk
set filename [tk_getOpenFile -multiple true]
puts $filename
运行(可能):
tclsh example.tcl