GUI에는 수많은 버튼이 들어갑니다. 각 버튼마다 표시되는 방법과 역할을 직접 지정할 수 있습니다. import sys from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QVBoxLayout class QPushButtonApp(QWidget): def __init__(self): super().__init__() self.initUI() def initUI(self): btn1 = QPushButton('버튼1', self) btn2 = QPushButton('버튼2', self) btn3 = QPushButton('버튼3', self) btn1.setCheckable(True) btn1.toggle() btn2.setText('버튼이름'..
정렬 방식 중 그리드 방식 있습니다. 상대배치로 창 크기에 따라 동적으로 크기가 조절되며 박스 레이아웃과 다르게 테이블 구조로 되어 있습니다. 비율이 아닌 행과 열의 정보를 입력하여 배치합니다. import sys from PyQt5.QtWidgets import QApplication, QWidget, QGridLayout, QLabel, QLineEdit, QTextEdit class gridLayoutApp(QWidget): def __init__(self): super().__init__() self.initUI() def initUI(self): grid = QGridLayout() self.setLayout(grid) grid.addWidget(QLabel('그리드1'), 0, 0) grid...
이전에 절대배치에 대해서 알아보았는데, 이번에는 상대배치를 만들어 보았습니다. pyqt5에서는 '박스'라는 개념을 사용하는데 가로박스와 세로박스로 구분하며 사용자는 박스의 위치를 비율로 입력합니다. 그러면 창 크기가 달라져도 그에 맞추어 자동으로 위치가 맞추어집니다. import sys from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QHBoxLayout, QVBoxLayout class boxLayoutApp(QWidget): def __init__(self): super().__init__() self.initUI() def initUI(self): btn_ok = QPushButton('확인') btn_cancel = QPushBut..
GUI 프로그램에서 각 요소의 배치는 아주 중요한 부분입니다. 버튼 배치에 따라서 사용성이 크게 달라질 수 있기 때문입니다. 레이아웃은 몇 가지 방법이 있는데 그중 하나가 사용자가 지정한 위치 배치하는 절대배치 방법을 알아봅니다. 사용자가 위치값만 입력하면 되기 떄문에 편히라지만 위치가 고정되어 있기 떄문에 동적으로 조절되지 않습니다. import sys from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QPushButton class absoultePositionApp(QWidget): def __init__(self): super().__init__() self.initUI() def initUI(self): label1 = QLabel('기능1..