D
D
DenisPy132018-01-24 17:26:08
Python
DenisPy13, 2018-01-24 17:26:08

How to output text from QTextEdit to text variable?

self.le = QTextEdit(self)
text = self.le.toPlainText()
        td = QTextDocument()
        td.setPlainText(text)
        message = td.encode("utf8")

I tried this, it doesn’t work (
How can I output text from QTextEdit to the text variable?
What would the program then encrypt (text from QTextEdit) and write to a separate file)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2018-01-24
@DenisPy13

So try

import sys

from PyQt5.QtWidgets import *
import rsa

class Example(QMainWindow):
    def __init__(self):
        super().__init__()
        
        self.setWindowTitle("Пример")

        self.textBrowser = QTextBrowser(self)
        self.textBrowser.move(0, 50)
        
        self.textEdit = QTextEdit(self)
        self.textEdit.append("Hello world!")

        text = self.textEdit.toPlainText()

        

        (pubkey, privkey) = rsa.newkeys(700)

        # шифруем
        crypto = rsa.encrypt(text.encode(), pubkey)
        print(crypto)

        # записываем в файл
        file = open("my_file.bin", "wb").write(crypto)

        # открываем файл в режиме чтения байтов
        file = open("my_file.bin", "rb").read()
        
        #расшифровываем
        self.text = rsa.decrypt(file, privkey)
        self.textBrowser.append(self.text.decode())
        print(text)

if __name__ == '__main__':
    app = QApplication(sys.argv)
    form = Example()
    form.show()
    app.exec()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question