[英]Python 3 - Open and Save files full contents
我正在尝试使用“askopenfilename”打开一个文件,然后将该文件的内容保存到一个新文件中。 然后我可以打开那个新文件进行修改。 但是,当我尝试这样做时,我遇到了错误。 任何帮助表示赞赏。
def startapp(self):
self.grid()
filebutton = tkinter.Button(self, text="Open File for Selection button", command=self.getfile)
filebutton.grid(column=1, row=0)
quitbutton = tkinter.Button(self, text="Quit", command=quit)
quitbutton.grid(column=2, row=0)
self.grid_columnconfigure(0, weight=1)
def getfile(self): #this is the open file function
selectedfile = filedialog.askopenfilename(filetypes=[('All files', '*.*')])
temp = tempfile.TemporaryFile()
temp.write(selectedfile)
提供的错误:
Exception in Tkinter callback Traceback (most recent call last):
File "C:\Python34\lib\tkinter\__init__.py", line 1533, in __call__
return self.func(*args)
File "C:/Users/**/PycharmProjects/FileAnalyser/FileAnalyser1/GUI/ParentWindow.py", line 31, in getfile
temp.write(selectedfile)
File "C:\Python34\lib\tempfile.py", line 399, in func_wrapper
return func(*args, **kwargs)
TypeError: 'str' does not support the buffer interface
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.