๋ชฉ์ฐจ
1 .Hello World
import sys,os
import PyQt5
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):
layout = QVBoxLayout()
label_widget = QLabel("Hello world!")
layout.addWidget(label_widget)
self.setLayout(layout)
self.show()
if __name__ =='__main__':
app = QApplication(sys.argv)
main = Main()
sys.exit(app.exec_())
์คํ ํ๋ฉด
์ ๋ ์ด์์์ ๋ฃ์ด์ค ์์ ฏ์ ๋ผ๋ฒจ ์์ ฏ ํ๋์ด๋ฏ๋ก ์ Hello world! ๊ฐ ์ถ๋ ฅ๋๋ค.
์ฐฝ ํฌ๊ธฐ ํค์์ฃผ๊ธฐ
#์ฐฝ ํฌ๊ธฐ๋ฅผ ํค์๋ณด์
self.resize(500,500)
self.show()
๋ฒํผ ์์ ฏ ์ถ๊ฐ
def init_ui(self):
layout = QVBoxLayout()
label_widget = QLabel("Hello world!")
button_widget = QPushButton("click me")
layout.addWidget(button_widget)
layout.addWidget(label_widget)
self.setLayout(layout)
์ฝค๋ณด ๋ฐ์ค ์์ ฏ ์ถ๊ฐ
def init_ui(self):
layout = QVBoxLayout()
label_widget = QLabel("Hello world!")
button_widget = QPushButton("click me")
combo_widget = QComboBox()
layout.addWidget(combo_widget)
layout.addWidget(button_widget)
layout.addWidget(label_widget)
self.setLayout(layout)
def init_ui(self):
layout = QVBoxLayout()
label_widget = QLabel("Hello world!")
button_widget = QPushButton("click me")
combo_widget = QComboBox()
combo_widget.addItem("Python")
combo_widget.addItem("c")
combo_widget.addItem("kotlin")
combo_widget.addItem("c++")
combo_widget.addItem("java")
layout.addWidget(combo_widget)
layout.addWidget(button_widget)
layout.addWidget(label_widget)
self.setLayout(layout)
์ฒดํฌ ๋ฐ์ค ์์ ฏ ๋ง๋ค๊ธฐ
def init_ui(self):
layout = QVBoxLayout()
label_widget = QLabel("Hello world!")
button_widget = QPushButton("click me")
combo_widget = QComboBox()
combo_widget.addItem("Python")
combo_widget.addItem("c")
combo_widget.addItem("kotlin")
combo_widget.addItem("c++")
combo_widget.addItem("java")
check_box_summer_widget = QCheckBox("Summer")
check_box_winter_widget = QCheckBox("Winter")
layout.addWidget(label_widget)
layout.addWidget(combo_widget)
layout.addWidget(button_widget)
layout.addWidget(check_box_winter_widget)
layout.addWidget(check_box_summer_widget)
self.setLayout(layout)
#์ฐฝ ํฌ๊ธฐ๋ฅผ ํค์๋ณด์
self.resize(500,500)
self.show()
radio ๋ฒํผ ์์ ฏ ๋ง๋ค๊ธฐ
radio ๋ฒํผ: ์ฌ๋ฌ ๋ฒํผ ์ค ํ๋๋ง ์ ํ ๊ฐ๋ฅํ๋ค.
def init_ui(self):
layout = QVBoxLayout()
label_widget = QLabel("Hello world!")
button_widget = QPushButton("click me")
combo_widget = QComboBox()
combo_widget.addItem("Python")
combo_widget.addItem("c")
combo_widget.addItem("kotlin")
combo_widget.addItem("c++")
combo_widget.addItem("java")
check_box_summer_widget = QCheckBox("Summer")
check_box_winter_widget = QCheckBox("Winter")
radio_button_widget_male = QRadioButton("male")
radio_buttion_widget_female = QRadioButton("female")
layout.addWidget(label_widget)
layout.addWidget(combo_widget)
layout.addWidget(button_widget)
layout.addWidget(check_box_winter_widget)
layout.addWidget(check_box_summer_widget)
layout.addWidget(radio_button_widget_male)
layout.addWidget(radio_buttion_widget_female)
self.setLayout(layout)
์คํ ๋ฐ์ค ์์ ฏ ์ถ๊ฐํ๊ธฐ
def init_ui(self):
layout = QVBoxLayout()
label_widget = QLabel("Hello world!")
button_widget = QPushButton("click me")
combo_widget = QComboBox()
combo_widget.addItem("Python")
combo_widget.addItem("c")
combo_widget.addItem("kotlin")
combo_widget.addItem("c++")
combo_widget.addItem("java")
check_box_summer_widget = QCheckBox("Summer")
check_box_winter_widget = QCheckBox("Winter")
radio_button_widget_male = QRadioButton("male")
radio_buttion_widget_female = QRadioButton("female")
spin_box_widget = QSpinBox()
layout.addWidget(label_widget)
layout.addWidget(combo_widget)
layout.addWidget(button_widget)
layout.addWidget(check_box_winter_widget)
layout.addWidget(check_box_summer_widget)
layout.addWidget(radio_button_widget_male)
layout.addWidget(radio_buttion_widget_female)
layout.addWidget(spin_box_widget)
self.setLayout(layout)
def init_ui(self):
layout = QVBoxLayout()
label_widget = QLabel("Hello world!")
button_widget = QPushButton("click me")
combo_widget = QComboBox()
combo_widget.addItem("Python")
combo_widget.addItem("c")
combo_widget.addItem("kotlin")
combo_widget.addItem("c++")
combo_widget.addItem("java")
check_box_summer_widget = QCheckBox("Summer")
check_box_winter_widget = QCheckBox("Winter")
radio_button_widget_male = QRadioButton("male")
radio_buttion_widget_female = QRadioButton("female")
spin_box_widget = QSpinBox()
date_widget= QDateEdit()
time_widget = QTimeEdit()
list_widget = QListWidget()
item_1 = QListWidgetItem("cat")
item_2 = QListWidgetItem("dog")
list_widget.addItem(item_1)
list_widget.addItem(item_2)
layout.addWidget(label_widget)
layout.addWidget(combo_widget)
layout.addWidget(button_widget)
layout.addWidget(check_box_winter_widget)
layout.addWidget(check_box_summer_widget)
layout.addWidget(radio_button_widget_male)
layout.addWidget(radio_buttion_widget_female)
layout.addWidget(spin_box_widget)
layout.addWidget(date_widget)
layout.addWidget(time_widget)
layout.addWidget(list_widget)
self.setLayout(layout)
#์ฐฝ ํฌ๊ธฐ๋ฅผ ํค์๋ณด์
self.resize(500,500)
self.show()
728x90
'2022 > ์คํ์์ค ์ํํธ์จ์ด ํ๋ก์ ํธ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
QGridLayout (0) | 2022.11.23 |
---|---|
GUI ๊ฐ์ 5 (0) | 2022.11.23 |
GUI ๊ฐ์ 4 (0) | 2022.11.22 |
GUI ๊ฐ์3 (0) | 2022.11.21 |
GUI ๊ฐ์2: ๋ ์ด์์ (0) | 2022.11.20 |