-- coding: utf-8 --
''' 【简介】 PyQt5中 QFontDialog 例子
'''
import sys from PyQt5.QtCore import * from PyQt5.QtGui import * from PyQt5.QtWidgets import *
class FontDialogDemo(QWidget): def init(self, parent=None): super(FontDialogDemo, self).init(parent) layout = QVBoxLayout() self.fontButton = QPushButton("choose font") self.fontButton .clicked.connect(self.getFont) layout.addWidget(self.fontButton ) self.fontLineEdit = QLabel("Hello,测试字体例子") layout.addWidget(self.fontLineEdit ) self.setLayout(layout) self.setWindowTitle("Font Dialog 例子")
代码语言:javascript复制def getFont(self):
font, ok = QFontDialog.getFont()
if ok:
self.fontLineEdit .setFont(font)
if name == 'main': app = QApplication(sys.argv) demo = FontDialogDemo() demo.show() sys.exit(app.exec_())