import sys
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
class QFontDialogDemo(QWidget):
def __init__(self):
super(QFontDialogDemo, self).__init__()
self.initUI()
def initUI(self):
self.setWindowTitle('输入对话框')
self.fontButton = QPushButton('FontDialog例子')
self.fontButton.clicked.connect(self.getFont)
self.fontLable = QLabel('Hello, 测试字体例子')
layout = QVBoxLayout()
layout.addWidget(self.fontButton)
layout.addWidget(self.fontLable)
self.setLayout(layout)
def getFont(self):
font, ok = QFontDialog.getFont()
if ok:
self.fontLable.setFont(font)
if __name__ == '__main__':
app = QApplication(sys.argv)
win = QFontDialogDemo()
win.show()
sys.exit(app.exec_())