0

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

1 Answer 1

1
  • 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())
Sign up to request clarification or add additional context in comments.

6 Comments

It gives me this error when I click the open button File "E:\Mike's CPT-135 python class\Project2\src\GroupProject.py", line 226, in _open file.read() io.UnsupportedOperation: not readable
Does the file exist yet?
it's not opening it to the text field aka not pad
Strange, I can't see why you'd get that error with the above code.
it's creating a text file, but I want it to open up in a note pad I have with in my program
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.