I am having trouble, trying to get my open button to open a text file. I want it to open the text file into the not pad, when I click the open button. If some one could help me or tell me what I am doing wrong, I would appreciate it.
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
line. file
as a variable name, it's also a type. read
. 'a'
is a flag for appending a file, use 'r'
(for read) instead. Try something like:
def _open(self):
with open("../Address.txt", "r") as the_file:
self._outputArea.insert("1.0", the_file.read())
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.