PyQt5字体对话框

import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *


class QFontDialogDemo(QWidget):
    def __init__(self):
        super(QFontDialogDemo,self).__init__()
        self.initUI()

    def initUI(self):
        self.setWindowTitle('Font Dialog案例')
        self.resize(300,200)
        layout =QVBoxLayout()

        self.fontbtn = QPushButton('选择字体')
        self.fontbtn.clicked.connect(self.getFont)
        self.fontlabel =QLabel('测试字体')
        self.fontlabel.setAlignment(Qt.AlignCenter)

        layout.addWidget(self.fontbtn)
        layout.addWidget(self.fontlabel)

        self.setLayout(layout)

    def getFont(self):
        font,ok = QFontDialog.getFont()
        if ok:
            self.fontlabel.setFont(font)

if __name__ == '__main__':
    app =QApplication(sys.argv)
    main = QFontDialogDemo()
    main.show()
    app.exit(app.exec_())

PyQt5字体对话框_第1张图片

你可能感兴趣的:(PyGt5,GUI)