UI

반응형



아래와 같은 ui를 만든 후 naver.ui로 저장

UI 구조 - 각 클래스와 객체명 


naver.ui 를 열어보면 xml형태로 작성되어 있음


이 파일을 파이썬 .py 파일로 변환하기

파일있는 폴더경로로 이동해서 cmd 창에서 pyuic5 -x naver.ui -o naver.py  실행

그럼 naver.py 생성

naver.py를 열어보면

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# -*- coding: utf-8 -*-
 
# Form implementation generated from reading ui file 'naver.ui'
#
# Created by: PyQt5 UI code generator 5.11.2
#
# WARNING! All changes made in this file will be lost!
 
from PyQt5 import QtCore, QtGui, QtWidgets
 
class Ui_Dialog(object):
    def setupUi(self, Dialog):
        Dialog.setObjectName("Dialog")
        Dialog.resize(158234)
        self.textBrowser = QtWidgets.QListWidget(Dialog)
        self.textBrowser.setGeometry(QtCore.QRect(1016014161))
        self.textBrowser.setObjectName("textBrowser")
        self.label = QtWidgets.QLabel(Dialog)
        self.label.setGeometry(QtCore.QRect(70101616))
        self.label.setObjectName("label")
        self.label_2 = QtWidgets.QLabel(Dialog)
        self.label_2.setGeometry(QtCore.QRect(70702116))
        self.label_2.setObjectName("label_2")
        self.pushButton = QtWidgets.QPushButton(Dialog)
        self.pushButton.setGeometry(QtCore.QRect(401307523))
        self.pushButton.setObjectName("pushButton")
        self.lineEdit_ID= QtWidgets.QLineEdit(Dialog)
        self.lineEdit_ID.setGeometry(QtCore.QRect(203011320))
        self.lineEdit_ID.setObjectName("lineEdit")
        self.lineEdit_PW= QtWidgets.QLineEdit(Dialog)
        self.lineEdit_PW.setGeometry(QtCore.QRect(209011320))
        self.lineEdit_PW.setObjectName("lineEdit_2")
 
        self.retranslateUi(Dialog)
        QtCore.QMetaObject.connectSlotsByName(Dialog)
 
    def retranslateUi(self, Dialog):
        _translate = QtCore.QCoreApplication.translate
        Dialog.setWindowTitle(_translate("Dialog""Dialog"))
        self.label.setText(_translate("Dialog""ID"))
        self.label_2.setText(_translate("Dialog""PW"))
        self.pushButton.setText(_translate("Dialog""시작"))
 
 
if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    Dialog = QtWidgets.QDialog()
    ui = Ui_Dialog()
    ui.setupUi(Dialog)
    Dialog.show()
    sys.exit(app.exec_())
cs

위와 같이 자동으로 코드로 변환되어 있음. 이 코드 안에서 이벤트를 연결하여 기능을 구현할 수 있음


반응형

+ Recent posts