QMessageBox.question一种偷懒的快速对话框
使用QMessageBox.question可以直接弹出带选择按钮的对话框,然后可以通过判定来获取用户的选择结果。这样可以省下了写界面的时间。
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
class ShowInfo(QDialog):
def __init__(self,show):
super(ShowInfo, self).__init__()
self.setWindowTitle('Workhour')
self.setMinimumWidth(200)
self.setMinimumHeight(200)
self.main_layout=QVBoxLayout()
self.btn=QPushButton('ddd')
self.btn.clicked.connect(self.test)
self.text_brow=QTextBrowser()
self.text_brow.setText(show)
self.main_layout.addWidget(self.text_brow)
self.main_layout.addWidget(self.btn)
self.setLayout(self.main_layout)
def test(self):
result=QMessageBox.question(self, '提示', '是否保存文件并输出', QMessageBox.Yes | QMessageBox.No, QMessageBox.No) #默认关闭界面选择No
if result==QMessageBox.Yes:
print('OK')
else:
print('No')
if __name__ == '__main__':
app=QApplication(sys.argv)
s=ShowInfo('OK')
s.show()
sys.exit(app.exec_())
结果: