简体   繁体   中英

Python Open File Button

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()
  • Why open and close the file first? Just use the with line.
  • Don't use file as a variable name, it's also a type.
  • You're not calling 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.

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