슬로건 타이틀

슬로건 상세문구

Python 공부/Tip

[파이썬] 파이썬으로 GUI 프로그램 만들어보기 #1

하루레몬하나 2023. 3. 6. 00:03
반응형
import sys
from PyQt5.QtWidgets import QApplication, QWidget

class App(QWidget):

    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        self.setWindowTitle('My First Application')
        self.move(300, 300)
        self.resize(400, 200)
        self.show()

if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = App()
    sys.exit(app.exec())

 


import sys
from PyQt5.QtWidgets import QApplication, QWidget

sys 모듈은 파이썬 인터프리터를 직접 사용할 수 있게 해 줍니다.

PyQt5.QtWidgets 모듈은 사용자 인터페이스를 만들기 위한 다양한 클래스를 사용할 수 있게 해 줍니다.

 


class App(QWidget):

    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        self.setWindowTitle('My First Application')
        self.move(300, 300)
        self.resize(400, 200)
        self.show()

__init__() 메서드는 클래스의 객체가 생성될 때 자동으로 호출되는 생성자입니다.

super()는 부모 클래스를 호출하는 메서드입니다. super().__init__()을 사용하여 부모 클래스 QWidget의 생성자를 호출한 다음 initUI() 메서드를 호출하여 사용자 인터페이스를 초기화합니다.

setWindowTitle() 메서드는 타이틀바에 표시되는 창의 제목을 설정하고, move() 메서드는 창의 위치를 설정하고, resize() 메서드는 창의 크기를 설정하고, 마지막으로 show() 메서드를 사용하여 창을 화면에 표시합니다.

 


if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = App()
    sys.exit(app.exec())

app = QApplication(sys.argv)을 사용하여 QApplication 클래스의 인스턴스를 만듭니다.

ex = App()을 사용하여 App 클래스의 인스턴스를 만듭니다.

app.exec() 메서드는 이벤트 루프가 계속 실행되게 해 주고 이벤트 루프가 종료될 때 sys.exit() 메서드로 프로그램을 안전하게 종료시킵니다. 

 


https://docs.python.org/2/library/sys.html

 

28.1. sys — System-specific parameters and functions — Python 2.7.18 documentation

28.1. sys — System-specific parameters and functions This module provides access to some variables used or maintained by the interpreter and to functions that interact strongly with the interpreter. It is always available. sys.argv The list of command li

docs.python.org

https://docs.python.org/ko/3/library/sys.html

 

sys — System-specific parameters and functions

This module provides access to some variables used or maintained by the interpreter and to functions that interact strongly with the interpreter. It is always available. Citations C99, ISO/IEC 9899...

docs.python.org

https://wikidocs.net/book/2165

 

PyQt5 Tutorial - 파이썬으로 만드는 나만의 GUI 프로그램

## 소개 - 한국어로 되어있는 PyQt5 자료가 많지 않아서 아래의 여러 튜토리얼과 강의의 예제를 정리하며 시작했습니다. - **PyQt5의 설치**부터 시작해서, **…

wikidocs.net

 

반응형