🍊

006 QLabel (라벨)

1. 코드

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_()
 

2. 상세 내용

이번 챕터에서는 라벨을 이용한 레이아웃 구성을 합니다. 라벨은 이미지나 글자, 영상 등의 콘텐츠를 담을 수 있는 오브젝트입니다. 많이 쓰이는 모듈중에 하나이니 아래 모듈들도 한 번 꼭 살펴보세요! 많이 쓰이는 것으로는 alignment, setPixmap, setText가 있습니다.
 
 
  • QPainter : 그림판 같은 역할을 하는 모듈입니다.
  • QLabel : 위에서 설명해드린 것처럼 라벨은 이미지나 글자, 영상 등의 콘텐츠를 담을 수 있습니다.

3. 실행화면

 
notion imagenotion image