๋ชฉ์ฐจ
Widget์ ์ด๋ฒคํธ๋ฅผ ์ฐ๊ฒฐํ์ฌ ์๋์ํค๊ธฐ
๊ธฐ๋ณธ ์ฝ๋
import sys
from PyQt5.QtWidgets import *
class Main(QDialog):
def __init__(self):
super().__init__()
self.init_ui()
def init_ui(self):
main_layout =QVBoxLayout()
self.setLayout(main_layout)
self.resize(400,400)
self.show()
if __name__ =='__main__':
app = QApplication(sys.argv)
main = Main()
sys.exit(app.exec_())
๋ฒํผ ์ถ๊ฐํ๊ธฐ
pushbutton = QPushButton("button1")
main_layout.addWidget(pushbutton)
์ด๋ฒคํธ ์ถ๊ฐํ๊ธฐ
pushbutton.clicked.connect()
()์ ํจ์๋ฅผ ์ง์ ํด์ฃผ๋ฉด ๋ฒํผ์ ํด๋ฆญํ์ ๋ ํด๋น ํจ์๊ฐ ์คํ๋ ์ ์๋๋ก ์ฐ๊ฒฐ๋๋ค.
pushbutton.clicked.connect(self.button_clicked)
def button_clicked(self):
print("button clicked")
self.lineedit=QLineEdit()
main_layout.addWidget(self.lineedit)
def button_clicked(self):
self.lineedit.setText("button clicked")
์ฝค๋ณด๋ฐ์ค ์ด๋ฒคํธ ์ถ๊ฐํ๊ธฐ
#์ฝค๋ณด๋ฐ์ค ์ด๋ฒคํธ
combobox = QComboBox()
combobox.addItems(["dog", "cat", "rabbit", "lion"])
combobox.currentTextChanged.connect(self.combobox_changed)
main_layout.addWidget(combobox)
self.lineedit_combobox = QLineEdit()
main_layout.addWidget(self.lineedit_combobox)
def combobox_changed(self, item):
self.lineedit_combobox.setText(item)
#์ฝค๋ณด๋ฐ์ค์์ ์ด๋ค ๋๋ฌผ์ด ์ ํ๋์๋์ง ์์์ผํ๊ณ (currentTextChanged ํจ์์ ์๋ค.)
# ๊ทธ ๋๋ฌผ์ textํํ๋ก ๋์์ฃผ์ผํ๋ค.
์ฒดํฌ ๋ฐ์ค ์ด๋ฒคํธ ์ถ๊ฐ
#์ฒดํฌ๋ฐ์ค ์ด๋ฒคํธ ์ฐ๊ฒฐ
checkbox = QCheckBox("item")
checkbox.stateChanged.connect(self.checkbox_changed)
main_layout.addWidget(checkbox)
self.lineedit_checkbox = QLineEdit()
main_layout.addWidget(self.lineedit_checkbox)
def checkbox_changed(self,state):
self.lineedit_checkbox.setText(str(state))
๋ผ๋์ค ๋ฒํผ
#๋ผ๋์ค ๋ฒํผ
radio1, radio2 = QRadioButton("A"), QRadioButton("B")
#๋ผ๋์ค ๋ฒํผ ์ด๋ฒคํธ on/off์ํ๊ฐ ๋ฐ๋๋ ๊ฒ -> toggled
radio1.toggled.connect(self.radio1_toggled)
radio2.toggled.connect(self.radio2_toggled)
main_layout.addWidget(radio1)
main_layout.addWidget(radio2)
self.lineedit_radio1 =QLineEdit()
self.lineedit_radio2 =QLineEdit()
main_layout.addWidget(self.lineedit_radio1)
main_layout.addWidget(self.lineedit_radio2)
def radio1_toggled(self, state):
self.lineedit_radio1.setText(str(state))
def radio2_toggled(self, state):
self.lineedit_radio2.setText(str(state))
728x90
'2022 > ์คํ์์ค ์ํํธ์จ์ด ํ๋ก์ ํธ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
QGridLayout (0) | 2022.11.23 |
---|---|
GUI ๊ฐ์ 5 (0) | 2022.11.23 |
GUI ๊ฐ์3 (0) | 2022.11.21 |
GUI ๊ฐ์2: ๋ ์ด์์ (0) | 2022.11.20 |
GUI ๊ฐ์ 1 (0) | 2022.11.20 |