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

Status
Not open for further replies.

salm2s

Honorable
Jul 21, 2017
266
6
10,815
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

Honorable
Jul 21, 2017
266
6
10,815
Hey so I did what you told me, and it works. But the problem is that once the user wants to change the url and save it, it just puts it after the first saved config:



Foc074J.png



s67Zxgw.png


How can i make it so that it replaces it?
 

salm2s

Honorable
Jul 21, 2017
266
6
10,815
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.
 
Status
Not open for further replies.