๋ชฉ์ฐจ
Fornlayout์ ์ด์ฉํ์ฌ ์๊ธฐ์๊ฐ UI๋ง๋ค๊ธฐ
์ ๋ณด๋ฅผ ์ ๋ ฅํ๊ฑฐ๋ ์ถ๋ ฅํ๋๋ฐ ๋ง์ด ์ด์ฉ๋๋ ํํ
ํ์๊ฐ์ , ์ ํ ์คํ ๋ฑ์ ํํํ๋๋ฐ ๋ง์ด ์ฌ์ฉ๋๋ค.
PyQt์์๋
QFormLayout์ ์ ๊ณตํ๋ค.
ํ์ค ํ์ค๋ง๋ค Lable: field ํํ์ ๋ฐฐ์น ์ ๊ณต
A : a
B : b
C : c
Label : Field
Widget : Widget
Label, Field ๋ชจ๋ QLabel
๋ณดํต Label์ text, Field์๋ widget
[๊ธฐ๋ณธ ์ฝ๋ฉ]
import sys
from PyQt5 import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
class Main(QDialog):
def __init__(self):
super().__init__()
self.init_ui()
def init_ui(self):
main_layout =QFormLayout()
self.setLayout(main_layout)
self.resize(500,500)
self.show()
if __name__ =='__main__':
app = QApplication(sys.argv)
main = Main()
sys.exit(app.exec_())
def init_ui(self):
main_layout =QFormLayout()
#์ด๋ฆ text๋ฅผ ์
๋ ฅํ ์ ์๋ widget
name_widget = QLineEdit()
#addRow ํ์ค ํ์ค ์
๋ ฅ
#addRow(label Widget, field Widget)
main_layout.addRow("Name: ",name_widget)
self.setLayout(main_layout)
self.resize(500,500)
self.show()
์์ผ
def init_ui(self):
main_layout =QFormLayout()
#์ด๋ฆ text๋ฅผ ์
๋ ฅํ ์ ์๋ widget
name_widget = QLineEdit()
#์์ผ ์
๋ ฅ
#๋
๋ ๋ฌ ์ผ์ ํด์ ์ด๊ฒ์ QHorizontalBox layout์ผ๋ก ๋ฌถ์ด์ค๋ค.
birthday_layout = QHBoxLayout()
year_widget = QComboBox()
month_widget= QComboBox()
date_widget = QComboBox()
birthday_layout.addWidget(year_widget)
birthday_layout.addWidget(month_widget)
birthday_layout.addWidget(date_widget)
for year in range(1900, 2023):
year_widget.addItem(str(year))
for month in range(1,13):
month_widget.addItem(str(month))
for date in range(1,32):
date_widget.addItem(str(date))
#addRow ํ์ค ํ์ค ์
๋ ฅ
#addRow(label Widget, field Widget)
#label์ Name, ์ค๋ฅธ์ชฝ์๋ ์ด๋ฆ์ ์
๋ ฅํ ์ ์๋ lineedit์ด ๋ฌ๋ค.
main_layout.addRow("Name: ", name_widget)
main_layout.addRow("Birthday: ", birthday_layout)
self.setLayout(main_layout)
self.resize(500,500)
self.show()
์ฃผ์ ์ ๋ ฅ
def init_ui(self):
main_layout =QFormLayout()
#์ด๋ฆ text๋ฅผ ์
๋ ฅํ ์ ์๋ widget
name_widget = QLineEdit()
#์์ผ ์
๋ ฅ
#๋
๋ ๋ฌ ์ผ์ ํด์ ์ด๊ฒ์ QHorizontalBox layout์ผ๋ก ๋ฌถ์ด์ค๋ค.
birthday_layout = QHBoxLayout()
year_widget = QComboBox()
month_widget= QComboBox()
date_widget = QComboBox()
birthday_layout.addWidget(year_widget)
birthday_layout.addWidget(month_widget)
birthday_layout.addWidget(date_widget)
for year in range(1900, 2023):
year_widget.addItem(str(year))
for month in range(1,13):
month_widget.addItem(str(month))
for date in range(1,32):
date_widget.addItem(str(date))
#์ฃผ์
address_layout = QVBoxLayout()
address_1 =QComboBox()
address_1.addItems( ["Seoul","Daejeon","Daegu","Busan"])
address_2 = QLineEdit()
address_layout.addWidget(address_1)
address_layout.addWidget(address_2)
#addRow ํ์ค ํ์ค ์
๋ ฅ
#addRow(label Widget, field Widget)
#label์ Name, ์ค๋ฅธ์ชฝ์๋ ์ด๋ฆ์ ์
๋ ฅํ ์ ์๋ lineedit์ด ๋ฌ๋ค.
main_layout.addRow("Name: ", name_widget)
main_layout.addRow("Birthday: ", birthday_layout)
main_layout.addRow("Address: ", address_layout)
self.setLayout(main_layout)
self.resize(500,500)
self.show()
์ด๋ฉ์ผ ์ ๋ ฅ
์๋ ๋ด์ฉ ์ถ๊ฐํ๊ธฐ
#์ด๋ฉ์ผ
email_layout = QHBoxLayout()
email_id = QLineEdit()
email_company = QLineEdit()
email_layout.addWidget(email_id)
email_layout.addWidget( QLabel("@"))
email_layout.addWidget(email_company)
#addRow ํ์ค ํ์ค ์
๋ ฅ
#addRow(label Widget, field Widget)
#label์ Name, ์ค๋ฅธ์ชฝ์๋ ์ด๋ฆ์ ์
๋ ฅํ ์ ์๋ lineedit์ด ๋ฌ๋ค.
main_layout.addRow("Name: ", name_widget)
main_layout.addRow("Birthday: ", birthday_layout)
main_layout.addRow("Address: ", address_layout)
main_layout.addRow("Email: " ,email_layout)
self.setLayout(main_layout)
self.resize(500,500)
self.show()
additems() ํ๋ฉด ํ๋ฒ์ ์ฌ๋ฌ๊ฐ์ ํ ์คํธ ์ ๋ ฅ ๊ฐ๋ฅํ๋ค.
email_combobox = QComboBox()
email_combobox.addItems(["google.com", "naver.com","daum.net"])
์ ํ๋ฒํธ ์ ๋ ฅ
#์ ํ๋ฒํธ
phone_number_layout= QHBoxLayout()
phone_number_layout.addWidget(QLineEdit())
phone_number_layout.addWidget(QLabel("-"))
phone_number_layout.addWidget(QLineEdit())
phone_number_layout.addWidget(QLabel("-"))
phone_number_layout.addWidget(QLineEdit())
#addRow ํ์ค ํ์ค ์
๋ ฅ
#addRow(label Widget, field Widget)
#label์ Name, ์ค๋ฅธ์ชฝ์๋ ์ด๋ฆ์ ์
๋ ฅํ ์ ์๋ lineedit์ด ๋ฌ๋ค.
main_layout.addRow("Name: ", name_widget)
main_layout.addRow("Birthday: ", birthday_layout)
main_layout.addRow("Address: ", address_layout)
main_layout.addRow("Email: " ,email_layout)
main_layout.addRow("Phone number: " ,phone_number_layout)
ํค
QSpinBox() ๋ ์ผ๋ฐ์ ์ผ๋ก ์ ์๋ฅผ ์ ๋ ฅํ๋ ์์ ฏ์ด๋ค.
๊ธฐ๋ณธ์ ์ผ๋ก ์ต๋๊ฐ์ด 99๋ก ์ค์ ๋์ด ์๋ค.
#ํค
height_widget = QSpinBox()
height_widget.setMaximum(250)
main_layout.addRow("Height: ", height_widget)
๊ฐ์ธ์ ๋ณด ์ด์ฉ ๋์ ์ฌ๋ถ
QCheckBox
#๋์
personal_info = QCheckBox("Agree?")
main_layout.addRow("Personal Information Share: ", personal_info)
์๊ธฐ์๊ฐ ํ ์ ์๋ ๊ณต๊ฐ
๊ทผ๋ฐ QLineEdit()์ ํ์ค๋ง ์ ๋ ฅํ ์ ์์ด์ ์ ํ์ด ์๋ค. ๊ทธ๋ด ๋๋ QPlainTextEdit()์ ์ฌ์ฉํด๋ณด์.
#์๊ธฐ์๊ฐ
self_intro = QPlainTextEdit()
main_layout.addRow("Self Introduction", self_intro)
์์ฑ ์๋ฃ ํ ์ ์ฅ ์ทจ์ ๋ฒํผ
#์ ์ฅ๋ฒํผ
save_cancel_layout = QHBoxLayout()
save_button = QPushButton("save")
cancel_button = QPushButton("cancel")
save_cancel_layout.addWidget(save_button)
save_cancel_layout.addWidget(cancel_button)
main_layout.addRow("",save_cancel_layout)
'2022 > ์คํ์์ค ์ํํธ์จ์ด ํ๋ก์ ํธ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
QGridLayout (0) | 2022.11.23 |
---|---|
GUI ๊ฐ์ 5 (0) | 2022.11.23 |
GUI ๊ฐ์ 4 (0) | 2022.11.22 |
GUI ๊ฐ์2: ๋ ์ด์์ (0) | 2022.11.20 |
GUI ๊ฐ์ 1 (0) | 2022.11.20 |