繁体   English   中英

Python打开文件按钮

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM