本文共 862 字,大约阅读时间需要 2 分钟。
import sysfrom 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_())
转载地址:http://eoben.baihongyu.com/