PyQt5-字体对话框:QFontDialog
"""
字体对话框:QFontDialog
"""
import sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
class QFontDialogDemo(QWidget):
def __init__(self):
super(QFontDialogDemo, self).__init__()
self.initUI()
def initUI(self):
self.setWindowTitle('Font Dialog 例子')
layout = QVBoxLayout()
self.fontButton = QPushButton('选择字体')
self.fontButton.clicked.connect(self.getFont)
layout.addWidget(self.fontButton)
self.fontLabel = QLabel('Hello, 测试字体例子')
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()
sys.exit(app.exec_())
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/18fc3cd00d52b17bb29e58fc600902dc.png)