0

code here

def button_clicked(self):
    self.lineedit.setText(
        open('test2.txt', 'r', encoding='uft_8')
        data = f.read()
        f.close()
        print(data))

error message SyntaxError: invalid syntax

Expected error resolution

mpx
  • 3,081
  • 2
  • 26
  • 56
jinhak
  • 1
  • 2
  • Does this answer your question? ['Syntax Error: invalid syntax' for no apparent reason](https://stackoverflow.com/questions/24237111/syntax-error-invalid-syntax-for-no-apparent-reason) – BrainFl Mar 18 '22 at 02:13
  • 1
    Please check how to call a function with multi variables first... – hochae Mar 18 '22 at 02:26

1 Answers1

3

Your are opening the file in the wrong place, try this:

def button_clicked(self):
    f = open('test2.txt', 'r', encoding='uft_8')
    data = f.read()
    f.close()
    self.lineedit.setText(data)

also there is a better way to open read data from a file

def button_clicked(self):
    with open('test2.txt', 'r', encoding='uft_8') as f
        data = f.read()
        self.lineedit.setText(data)
Apollo-Roboto
  • 623
  • 5
  • 21