-
Notifications
You must be signed in to change notification settings - Fork 0
/
QFontDiolog.py
41 lines (31 loc) · 906 Bytes
/
QFontDiolog.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"""
QFontDiolog
"""
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
import sys
class QFontDialogDemo (QWidget):
def __init__(self):
super().__init__()
self.initUi()
def initUi(self):
self.setWindowTitle("字体对话框")
self.resize(300,100)
layout= QVBoxLayout()
self.button=QPushButton("请选择字体")
self.button.clicked.connect(self.chooseFont)
self.label=QLabel('Hello World')
layout.addWidget(self.button)
layout.addWidget(self.label)
self.setLayout(layout)
def chooseFont(self):
#获取字体对话框的值
font,ok =QFontDialog.getFont()
#设置标签的字体
self.label.setFont(font)
if __name__ == '__main__':
app = QApplication(sys.argv)
main = QFontDialogDemo()
main.show()
sys.exit(app.exec_())