[英]Python Open File Button
我遇到了麻烦,试图让我的打开按钮打开文本文件。 当我单击打开按钮时,我希望它将文本文件打开到not pad中。 如果有人可以帮助我或告诉我我做错了什么,我将不胜感激。
def _open(self):
open("../Address.txt","r").close()
with open("../Address.txt", "a") as file:
self._outputArea.insert("1.0", file.read)
file.read()
with
行。 file
用作变量名,它也是一种类型。 read
。 'a'
是用于附加文件的标志,请改用'r'
(供读取)。 尝试类似:
def _open(self):
with open("../Address.txt", "r") as the_file:
self._outputArea.insert("1.0", the_file.read())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.