๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
2022/์˜คํ”ˆ์†Œ์Šค ์†Œํ”„ํŠธ์›จ์–ด ํ”„๋กœ์ ํŠธ

GUI ๊ฐ•์˜ 1

by hyeonha 2022. 11. 20.

๋ชฉ์ฐจ

    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