admin管理员组

文章数量:1660122

我正在研究复位按钮。该按钮用于清除文本小部件中生成的文本,并删除正在写入数据的文件。清除文本小部件可以工作,但是删除文件时遇到问题。在

当我试图从windows中删除它时,它说它仍然在Python中打开。所以,我先从代码中关闭了它,然后试图删除它,但没有成功。在

我已经编程了另一个按钮,这样它就不会覆盖文件。所以,我不能只删除文件中已经写入的数据。在

有没有办法可以强制删除那个文件??在

我使用的是python2.6.6。在

这是我在重置按钮上的代码:def reset_it(self):

self.run.update() # run is the other button, I have to stop it's processing!

self.Outputlines.update() # Forcing the TextWidget to update.

self.Outputlines.config(state=NORMAL)

self.Outputlines.delete(1.0, END) # Clearing everything from the TextWidget.

self.Outputlines.config(state=DISABLED)

self.run.wait_variable() # Stopping the run button.

self.infile.close() # Closing the file.

os.remove(self.filename.get()) # Code to delete the file.

本文标签: 文件PythonWindows