본문 바로가기
PyQt5_

빈 창

by 자동매매 2023. 3. 10.
from PyQt6.QtWidgets import QApplication, QWidget

# Only needed for access to command line arguments
import sys

# You need one (and only one) QApplication instance per application.
# Pass in sys.argv to allow command line arguments for your app.
# If you know you won't use command line arguments QApplication([]) works too.
app = QApplication(sys.argv)

# Create a Qt widget, which will be our window.
window = QWidget()
window.show()  # IMPORTANT!!!!! Windows are hidden by default.

# Start the event loop.
app.exec()


# Your application won't reach here until you exit and the event
# loop has stopped.

 

What’s the event loop?

Before getting the window on the screen, there are a few key concepts to introduce about how applications are organised in the Qt world. If you’re already familiar with event loops you can safely skip to the next section.

The core of every Qt Application is the QApplication class. Every application needs one — and only one — QApplication object to function. This object holds the event loop of your application — the core loop which governs all user interaction with the GUI.

Each interaction with your application — whether a press of a key, click of a mouse, or mouse movement — generates an event which is placed on the event queue. In the event loop, the queue is checked on each iteration and if a waiting event is found, the event and control is passed to the specific event handler for the event. The event handler deals with the event, then passes control back to the event loop to wait for more events. There is only one running event loop per application.

 

- The QApplication class

  • QApplication은 Qt 이벤트 루프를 보유합니다.
  • 하나의 QApplication 인스턴스가 필요합니다.
  • 응용 프로그램은 작업이 수행될 때까지 이벤트 루프에서 대기합니다.
  • 한 번에 하나의 이벤트 루프만 있습니다.

 

Basic Window

import sys

from PyQt6.QtCore import QSize, Qt
from PyQt6.QtWidgets import (
    QApplication,
    QMainWindow,
    QPushButton,
)  # <1>


# Subclass QMainWindow to customize your application's main window
class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()  # <2>

        self.setWindowTitle("My App")

        button = QPushButton("Press Me!")

        # Set the central widget of the Window.
        self.setCentralWidget(button)  # <3>


app = QApplication(sys.argv)

window = MainWindow()
window.show()

app.exec()

'PyQt5_' 카테고리의 다른 글

Layouts  (0) 2023.03.11
Widgets  (0) 2023.03.10
Signals & Slots  (0) 2023.03.10
Sizing windows and widgets  (0) 2023.03.10
index  (0) 2023.03.10

댓글