[SOLVED] Saving QLineEdit text to a variable in the python script

Status
Not open for further replies.

salm2s

Respectable
Jul 21, 2017
252
4
1,815
9
Hi there,
So i have a quick question: How can i save text a user inputted into LineEdit and save that text to a variable within the script?
I looked at some documentation and saw that you can save the text to another file:
Code:
def save_config(self):
    with open('config.txt', 'w') as f:
        url_text = self.lineEdit.text()
        f.write(url_text)
But when i do that it removes the variable i set in the txt file.

Thanks,
salm2s
 

salm2s

Respectable
Jul 21, 2017
252
4
1,815
9
read the file and replace the line?
Well, basically, I will already set a url so that the gui's set text will be: self.lineEdit.setText(config.URL). Then when the user sets a new URL and clicks save, it will change the URL to the website set by the user. And when the user launches the gui again, it will not be the text i set initially, but it will be what they set after they saved.
 

salm2s

Respectable
Jul 21, 2017
252
4
1,815
9
Lol. Don't worry about it, i found a solution, just used a .json file and wrote text to there. then i set lineedit.setText(test['URL']). Thanks for the help 👍
 
Status
Not open for further replies.

ASK THE COMMUNITY

TRENDING THREADS