PyQt5
: 파이썬에서 GUI프로그래밍을 할 때 사용하는 대표적인 패키지이다.
아나콘다(Anaconda)를 설치하면 기본적으로 디자이너(Designer)가 포함되어있다.
실행하기
방법1. 윈도우 탐색기에서 designer 실행
방법2. cmd(명령 프롬프트)에서 Qt Designer 를 입력하면 자동으로 프로그램 실행
디자인 설계하기
1. 버튼과 라벨 추가하기
objectName과 text 를 변경해준다.
main01.ui 완성하기
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>762</width>
<height>596</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QLabel" name="lbl">
<property name="geometry">
<rect>
<x>180</x>
<y>120</y>
<width>91</width>
<height>41</height>
</rect>
</property>
<property name="text">
<string>Good Morning</string>
</property>
</widget>
<widget class="QPushButton" name="pb">
<property name="geometry">
<rect>
<x>310</x>
<y>130</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>click</string>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>762</width>
<height>21</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>
디자인설계를 마치면 main01.ui 파일을 저장하자.
pyQt에서 디자인한 ui를 IDE(통합개발환경). 나는 eclipse를 통해 띄워보고
이벤트도 넣어주자
eclipse에서 ui 띄우기
main01.ui 파일을 workspace project -패키지에 추가해준다.
pyQt ui to py으로 검색을 통해 아래 코드를 찾을 수 있었다.
form_class = uic.loadUiType("main01.ui")[0] 자리에 ui파일명을 입력한다.
run을 실행하면 만든 화면이 뜰것이다.
import sys
from PyQt5 import uic
from PyQt5.QtWidgets import QMainWindow, QApplication, QMessageBox
from PyQt5.Qt import QLabel
form_class = uic.loadUiType("main01.ui")[0]
class MyWindow(QMainWindow, form_class):
def __init__(self):
super().__init__()
self.setupUi(self)
self.pb.clicked.connect(self.btn_clicked)
def btn_clicked(self):
self.lbl.setText("Good Evening")
if __name__ == "__main__":
app = QApplication(sys.argv)
myWindow = MyWindow()
myWindow.show()
app.exec_()
'공부 기록노트 > python' 카테고리의 다른 글
[python]day3. 파이큐티(PyQt5 ) - 홀 짝 게임 만들기 (0) | 2023.01.03 |
---|---|
[python]day3. 파이큐티(PyQt5 ) - 구구단 출력 (0) | 2023.01.03 |
[python]day3. 파이큐티(PyQt5 ) - 숫자 증가시키기 (0) | 2023.01.03 |
[python] day2. 파이썬 개발환경 세팅(전자정부프레임워크) (0) | 2023.01.01 |
[python] day1. GUI 프로그래밍을 위한 준비(IDE/아나콘다(Anaconda)) (0) | 2023.01.01 |