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