PyQt5--QFontDiaglog

 1 # -*- coding:utf-8 -*-
 2 '''
 3 Created on Sep 17, 2018
 4 
 5 @author: SaShuangYiBing
 6 
 7 Comment: 
 8 '''
 9 import sys
10 from PyQt5.QtWidgets import QApplication,QWidget,QFontDialog,QLabel,QVBoxLayout,QPushButton,QSizePolicy
11 
12 class New_test(QWidget):
13     def __init__(self):
14         super().__init__()
15         self.initUI()
16     
17     def initUI(self):
18         vbox = QVBoxLayout()
19         
20         btn = QPushButton('Diaglog',self)
21         btn.setSizePolicy(QSizePolicy.Fixed,QSizePolicy.Fixed)
22         btn.move(20,20)
23         btn.clicked.connect(self.showdiaglog)
24         
25         self.lbl = QLabel('Knowledge only matters',self)
26         self.lbl.move(150,20)
27         
28         vbox.addWidget(btn)
29         vbox.addWidget(self.lbl)
30         self.setLayout(vbox)
31         
32         self.setGeometry(300,300,250,180)
33         self.setWindowTitle('Font Diaglog')
34         self.show()
35         
36     def showdiaglog(self):
37         font,ok = QFontDialog.getFont()
38         if ok:
39             self.lbl.setFont(font)
40             
41 if __name__ == '__main__':
42     app = QApplication(sys.argv)
43     ex = New_test()
44     sys.exit(app.exec_())        

 

 

posted @ 2018-09-20 09:32  iSZ  阅读(265)  评论(0编辑  收藏  举报