簡體   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