class SecondWidget4(QtWidgets.QWidget): def __init__(self, parent=None): super().__init__(parent=parent) layout = QtWidgets.QVBoxLayout(self) label1 = QLabel('입력', self) label1.setAlignment(Qt.AlignVCenter) label1.move(200, 30) label2 = QLabel('결과', self) label2.setAlignment(Qt.AlignVCenter) label2.move(710, 30) self.text_dox1 = QTextEdit(self) self.text_dox1.resize(350, 350) self.text_dox1.move(50, 60) self.text_dox2 = QTextBrowser(self) self.text_dox2.append('') self.text_dox2.setGeometry(550, 60, 350, 350) self.dk_base64 = QPushButton("OK", self) self.dk_base64.setGeometry(50, 420, 850, 45) self.dk_base64.clicked.connect(self.base64_conversion) self.back = QPushButton(self) self.back.setStyleSheet( ''' QPushButton{image:url(./img/back_img.png); border:0px;} QPushButton:hover{image:url(./img/back_img_ev_1.png); border:0px;} ''') self.back.setGeometry(0, 0, 50, 50) self.back.clicked.connect(self.change_stack1) def change_stack1(self): self.parent().stack.setCurrentIndex(4) def base64_conversion(self): # print(self.text_dox1.toPlainText()) sitename_bytes = base64.b64decode(self.text_dox1.toPlainText()) sitename = sitename_bytes.decode('utf-8') print(sitename) # 내용 초기화 self.text_dox2.clear() self.text_dox2.repaint() self.text_dox2.append(str(sitename))
class SecondWidget1(QtWidgets.QWidget): def __init__(self, parent=None): super().__init__(parent=parent) layout = QtWidgets.QVBoxLayout(self) label1 = QLabel('입력', self) label1.setAlignment(Qt.AlignVCenter) label1.move(200, 30) label2 = QLabel('결과', self) label2.setAlignment(Qt.AlignVCenter) label2.move(710, 30) self.text_box1 = QTextEdit(self) self.text_box1.resize(350, 350) self.text_box1.move(50, 60) self.text_box2 = QTextBrowser(self) self.text_box2.append('') self.text_box2.setGeometry(550, 60, 350, 350) self.ok_base64 = QPushButton("OK", self) self.ok_base64.setGeometry(50, 420, 850, 45) self.ok_base64.clicked.connect(self.base64_conversion) self.back = QPushButton(self) self.back.setStyleSheet( ''' QPushButton{image:url(./img/back_img.png); border:0px;} QPushButton:hover{image:url(./img/back_img_ev_1.png); border:0px;} ''') self.back.setGeometry(0, 0, 50, 50) self.back.clicked.connect(self.change_stack1) def base64_conversion(self): ''' QTextEdit 사용 경우 .toPlainText() 사용 바람 https://doc.qt.io/qt-5/qplaintextedit.html#plainText-prop 참조 ''' # print(self.text_box1.toPlainText()) # Base64 변환 과정 inpututf = self.text_box1.toPlainText().encode('utf-8') # ascii 사용시 오류발생 utf-8으로 사용하세요 finalvalue = base64.b64encode(inpututf) print(finalvalue) ''' 내용 수정또는 추가시 내용 초기화 https://study-code.gitbook.io/python-basic/qtpy/pyqt-widget/application-make/widget-2#undefined-1 참조 ''' self.text_box2.clear() self.text_box2.repaint() ''' "b"와 따옴표없이 출력 .decode("utf-8") https://stackoverflow.com/a/45151048 참조 ''' self.text_box2.append(str(finalvalue.decode("utf-8"))) def change_stack(self): self.parent().stack.setCurrentIndex(0) def change_stack1(self): self.parent().stack.setCurrentIndex(1)