Answer the question
In order to leave comments, you need to log in
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")
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question