Michael Schultz
Michael Schultz

Reputation: 109

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()

Upvotes: 0

Views: 1008

Answers (1)

101
101

Reputation: 8979

  • 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())

Upvotes: 1

Related Questions