我正在处理重置按钮。该按钮应该清除文本窗口小部件中生成的文本,并删除正在写入数据的文件。清除文本小部件有效,但我在删除文件时遇到问题。
当我尝试从Windows中删除它时,它说它仍在Python中打开。所以,我先从我的代码中关闭它,然后尝试删除它但是没有用。
我已编程了另一个按钮,因此它不会覆盖文件。所以,我不能只删除已经写在文件中的数据。
有什么办法可以强行删除那个文件吗?
我正在使用Python 2.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.