PyQt5之QFontDialog(十五)

import sys
from PyQt5.QtWidgets import QWidget,QApplication,QLineEdit,QLabel,QFormLayout,QPushButton,QFontDialog


class fontDialogDemo(QWidget):
    def __init__(self):
        super(fontDialogDemo, self).__init__()

        #定义部件
        self.button = QPushButton("choose font")
        self.label = QLabel("font change")
        #self.line = QLineEdit()
        #self.line.setPlaceholderText("font change")

        #button信号
        self.button.clicked.connect(self.ChooseFont)

        #布局
        formlayout = QFormLayout()
        formlayout.addRow(self.button,self.label)

        self.setLayout(formlayout)
        self.setWindowTitle("FontDialog")

    def ChooseFont(self):
        font,ok = QFontDialog.getFont()  #调出Font对话框
        if font and ok:
            self.label.setFont(font)



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

参考:PyQt5基本控件详解之QFontDialog(十五)_jia666666的博客-CSDN博客

你可能感兴趣的:(PyQt,qt,开发语言)