File tree Expand file tree Collapse file tree 2 files changed +37
-1
lines changed
Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Original file line number Diff line number Diff line change 3838
3939* p22_表格中添加按钮 [ 源码下载] ( p22_表格中添加按钮 ) [ 博文地址] ( https://xugaoxiang.com/2022/03/21/pyqt5-22-add-button-to-table/ )
4040
41- * p23_自适应布局 [ 博文地址] ( https://xugaoxiang.com/2022/03/21/pyqt5-23-auto-fit-windows/ )
41+ * p23_自适应布局 [ 博文地址] ( https://xugaoxiang.com/2022/03/21/pyqt5-23-auto-fit-windows/ )
42+
43+ * p24_QMessageBox按钮自定义 [ 源码下载] ( p24_QMessageBox自定义按钮 ) [ 博文地址] ( https://xugaoxiang.com/2022/04/10/pyqt5-24-qmessagebox-button-customization/ )
Original file line number Diff line number Diff line change 1+ import sys
2+
3+ from PyQt5 .QtWidgets import QMainWindow , QApplication , QMessageBox , QPushButton
4+
5+
6+ class QMessageBoxDemo (QMainWindow ):
7+
8+ def __init__ (self , parent = None ):
9+ super (QMessageBoxDemo , self ).__init__ (parent )
10+ self .setWindowTitle ("QMessageBox demo" )
11+ self .resize (600 , 400 )
12+
13+ self .button = QPushButton (self )
14+ self .button .setText ("点击弹出QMessageBox" )
15+ self .button .resize (180 , 140 )
16+ self .button .move (200 , 100 )
17+ self .button .clicked .connect (self .showDialog )
18+
19+ def showDialog (self ):
20+ msgBox = QMessageBox (QMessageBox .Warning , "标题" , "消息正文" )
21+ yes = msgBox .addButton ("自定义Yes按钮" , QMessageBox .YesRole )
22+ no = msgBox .addButton ("自定义No按钮" , QMessageBox .NoRole )
23+ msgBox .exec_ ()
24+ if msgBox .clickedButton () == yes :
25+ print ('yes' )
26+ else :
27+ print ('no' )
28+
29+
30+ if __name__ == '__main__' :
31+ app = QApplication (sys .argv )
32+ demo = QMessageBoxDemo ()
33+ demo .show ()
34+ sys .exit (app .exec_ ())
You can’t perform that action at this time.
0 commit comments