HomeAboutMeBlogGuest
© 2025 Sejin Cha. All rights reserved.
Built with Next.js, deployed on Vercel
📟
PyQt 5 Lecture
/
🍊
006 QLabel (라벨)
🍊

006 QLabel (라벨)

1. 코드2. 상세 내용3. 실행화면

1. 코드

 

2. 상세 내용

이번 챕터에서는 라벨을 이용한 레이아웃 구성을 합니다. 라벨은 이미지나 글자, 영상 등의 콘텐츠를 담을 수 있는 오브젝트입니다. 많이 쓰이는 모듈중에 하나이니 아래 모듈들도 한 번 꼭 살펴보세요! 많이 쓰이는 것으로는 alignment, setPixmap, setText가 있습니다.
 
출처 : https://doc.qt.io/qtforpython/PySide2/QtWidgets/QLabel.html
출처 : https://doc.qt.io/qtforpython/PySide2/QtWidgets/QLabel.html
 
  • QPainter : 그림판 같은 역할을 하는 모듈입니다.
  • QLabel : 위에서 설명해드린 것처럼 라벨은 이미지나 글자, 영상 등의 콘텐츠를 담을 수 있습니다.
QLabel - Qt for Python
is used for displaying text or an image. No user interaction functionality is provided. The visual appearance of the label can be configured in various ways, and it can be used for specifying a focus mnemonic key for another widget.
QLabel - Qt for Python
https://doc.qt.io/qtforpython/PySide2/QtWidgets/QLabel.html

3. 실행화면

 
notion image
 
import sys from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QHBoxLayout from PyQt5.QtGui import QPixmap class 라벨(QWidget): def __init__(self): super().__init__() self.UI초기화() def UI초기화(self): licat = QLabel() pie = QLabel() sun = QLabel() licat.setStyleSheet( "border-style: solid;" "border-width: 3px;" "border-color: red;" "border-radius: 3px;" "image: url(img/weniv-licat.png)" ) pie.setStyleSheet( "border-style: double;" "border-width: 5px;" "border-color: blue;" "background-color: #87CEFA;" "image: url(img/weniv-pie.png)" ) sun.setStyleSheet( "border-style: dot-dot-dash;" "border-width: 5px;" "border-color: green;" "border-radius: 3px;" "background-color: beige;" "image: url(img/weniv-sun.png)" ) hbox = QHBoxLayout() hbox.addWidget(licat) hbox.addWidget(pie) hbox.addWidget(sun) self.setLayout(hbox) self.setGeometry(400, 400, 500, 400) self.setWindowTitle('라벨을 통한 꾸미기!') self.show() 프로그램무한반복 = QApplication(sys.argv) 실행인스턴스 = 라벨() 프로그램무한반복.exec_()