본문 바로가기

공부/Python

5.[Text]Qt Designer + PyQt5

반응형

입력으로는 Line edit, push button

출력으로는 Label, Textbrowser

 

pyuic5 -x text_box_ui.ui -o text_box_ui.py

일단 ui 파일을 py로 만들어 줍니다.

 

import sys
from PyQt5.QtWidgets import *
import text_box_ui

class MyWindow(QMainWindow, text_box_ui.Ui_MainWindow):
    def __init__(self):
        super().__init__()
        self.setupUi(self)

        self.lineEdit.returnPressed.connect(self.line_edit_function)
        self.pushButton.clicked.connect(self.push_btn_function)

    def line_edit_function(self):
        self.label.setText(self.lineEdit.text())
        self.textBrowser.append(self.lineEdit.text())
        self.lineEdit.clear()

    def push_btn_function(self):
        self.line_edit_function()
        self.lineEdit.setFocus()

if __name__ == "__main__":
    app = QApplication(sys.argv)
    myApp = MyWindow()
    myApp.show()
    app.exec_()

반응형

'공부 > Python' 카테고리의 다른 글

7.[Thread]Qt Designer + PyQt5  (0) 2021.06.05
6.[Scroll Area]Qt Designer + PyQt5  (0) 2021.05.25
4.[check box]Qt Designer + PyQt5  (0) 2021.05.07
3.[Radio Button]Qt Designer + PyQt5  (0) 2021.05.07
2.[Dialog]Qt Designer + PyQt5  (0) 2021.05.06