PyQT5之label


from PyQt5 import QtWidgets
from PyQt5 import QtCore, QtGui
import sys


if __name__ == '__main__':

    app = QtWidgets.QApplication(sys.argv)
    main_win = QtWidgets.QMainWindow()
    main_win.setWindowTitle("我的第一个PyQT5应用")
    label = QtWidgets.QLabel()
    label.setText("Hello, PyQT5")
    # label.setBaseSize(100, 150)
    # label.setScaledContents()
    # pix = pixmap.scaled(QtCore.QSize(620, 500), QtCore.Qt.KeepAspectRatio)  # 自动保持比例放缩方式
    # label.setPixmap(pix)   # 设置图像显示
    label.setAlignment(QtCore.Qt.AlignCenter)   # label上居中显示
    label.setStyleSheet("background-color:blue;color:green")    # 背景颜色设置
    font = QtGui.QFont()
    font.setBold(True)
    font.setPointSizeF(32)
    label.setFont(font)
    main_win.setCentralWidget(label)
    main_win.setMinimumSize(1080, 720)
    main_win.show()
    app.exec_()

posted @ 2024-06-04 15:39  星空28  阅读(8)  评论(0编辑  收藏  举报