Saving Text From Qplaintextedit By Qfiledialog And Creating .txt File
I have troubles with saving note(text from QPlainTextEdit). I need only saving in txt format. After typing text and clicking button program displays error 'expected string or bytes
Solution 1:
The error is because you are not actually using the returned data from the file dialog:
def saveac(self):
path = QFileDialog.getSaveFileName(self, "Save file", "", "Text files (*.txt)")
ifnotpath:
returnself._save_to_path(self.path) # <-- here!
Also, the getSaveFileName static returns a tuple composed of file path and selected filter strings, and both of them could be empty if the dialog is cancelled, so if not path
would always fail.
Check the returned data and call the _save_to_path accordingly:
def saveac(self):
path, filter = QFileDialog.getSaveFileName(self, "Save file", "", "Text files (*.txt)")
ifnotpath:
returnself._save_to_path(path)
Post a Comment for "Saving Text From Qplaintextedit By Qfiledialog And Creating .txt File"