a message box to confirm the action
当点击窗口的X按钮时,弹出确认退出消息框,继续点击Yes,退出。否则,窗口继续处于打开状态

代码:
"""
This program shows a confirmation
message box when we click on the close
button of the application window.
"""
import sys
from PyQt5.QtWidgets import QWidget, QMessageBox, QApplication class Example(QWidget): def __init__(self):
super().__init__() self.initUI() def initUI(self): self.setGeometry(300, 300, 250, 150)
self.setWindowTitle('Message box')
self.show() def closeEvent(self, event): reply = QMessageBox.question(self, 'Message',
"Are you sure to quit?", QMessageBox.Yes |
QMessageBox.No, QMessageBox.No) if reply == QMessageBox.Yes:
event.accept()
else:
event.ignore() if __name__ == '__main__': app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
If we close a QWidget, the QCloseEvent is generated. To modify the widget behaviour we need to reimplement the closeEvent() event handler.
reply = QMessageBox.question(self, 'Message',
"Are you sure to quit?", QMessageBox.Yes |
QMessageBox.No, QMessageBox.No)

The first string appears on the titlebar. 即上图中的'Message'
The second string is the message text displayed by the dialog. 即上图中的"Are you sure to quit?"
The third argument specifies the combination of buttons appearing in the dialog. 即上图中的Yes和No组合
The last parameter is the default button. It is the button which has initially the keyboard focus.
默认选中button,如上图是No,直接enter即退出窗口
The return value is stored in the reply variable.
a message box to confirm the action的更多相关文章
- Wix: Show conditional message box
For example: Scenario: Show message box only during installation and MYPROPERTY has to be equal to & ...
- Message Box Position
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- mint-ui message box 问题;
当引用 mint-ui message box 的 出现的问题,我暂时是不知道为什么: 官网是这样写的: 于是 我也这么做的:(这里用小写,具体我也不清楚,毕竟文档上写的也不是很清楚,但是只有这样写, ...
- vue 结合mint-ui Message box的使用方法
两种方式使用: 一.全局注册 1.在main.js中引入 //引入 import { MessageBox } from 'mint-ui'; //全局使用,挂载到原型上 Vue.prototyp ...
- message box
QMessageBox 弹出框上的按钮设置为中文 Qt 默认的弹出框上的按钮式英文,虽然也知道是什么意思,但终究不如中文看着顺眼. QMessageBox box(QMessageBox::War ...
- Qt学习笔记-制作一个计算器-对话框Message Box
在做计算器的前提先做一个加法器. 设计界面. 在点击计算的时候,获取前两个输入框中的数据相加后显示在第三个输入框. toInt是将字符串转换为数字.number静态函数是将数字转化为字符串. 加法器已 ...
- Model-View-ViewModel (MVVM) Explained 转摘自:http://www.wintellect.com/blogs/jlikness/model-view-viewmodel-mvvm-explained
The purpose of this post is to provide an introduction to the Model-View-ViewModel (MVVM) pattern. W ...
- github pages
http://zyip.github.io/facemaker/index echo "hello world" >>hello.htm git init git ad ...
- Yii2美化confirm
在view中, <?= Html::a('删除', ['post/delete', 'id' => $post['id']],['data-confirm'=>'确定要删除吗?']) ...
随机推荐
- camp待补
待修莫对 序列自动机 几何积分 沈阳 M 待删除背包 : 分组背包 K-LIS, K次二分(插到最后stop) 问题转化为LIS bzoj2131 hdu4055 最小线段覆盖环 实时路况 分治+f ...
- No setter found for property 'cronExpression' in class 'org.springframework.scheduling.quartz.CronTriggerBean'
今天想写个Spring集成Quartz的小Demo,结果报错cronExpression未定义,通过差错,原来是因为Spring 3.0.5与Quartz2.2.2不兼容,Spring3.1以下的只能 ...
- 2017-2018-1 20155208 课堂测试(ch06)(补做)
2017-2018-1 20155208 课堂测试(ch06)(补做) 1.( 多选题 | 1 分) 下面说法正确的是(ABC) A . 存储层次结构中最小的缓存是寄存器 B . 存储层次结构的中心思 ...
- random module
import random # 方法返回随机生成的一个实数,它在[0,1)范围内print(random.random())运行结果:0.06435148447021877 # 方法返回随机生成的一个 ...
- maven 总结整理(二)——download source code
当我们用maven下载jar包时,有时希望下载jar包的源代码,此时可以在pom.xml文件中,进行设置. <build> <finalName>WebProject&l ...
- https://blog.csdn.net/qq_35447305/article/details/78587691
来源:https://blog.csdn.net/qq_35447305/article/details/78587691 需要去查看设置.C:\Users\用户名 目录下找到 .npmrc文件,删除 ...
- BZOJ1494 [NOI2007]生成树计数
题意 F.A.Qs Home Discuss ProblemSet Status Ranklist Contest 入门OJ ModifyUser autoint Logout 捐赠本站 Probl ...
- DevExpress使用方法GridControl总结
1.隐藏最上面的GroupPanel gridView1.OptionsView.ShowGroupPanel=false; 2.得到当前选定记录某字段的值 sValue=Table.Rows[gri ...
- NPOI之Excel——设置单元格背景色
NPOI Excel 单元格颜色对照表,在引用了 NPOI.dll 后可通过 ICellStyle 接口的 FillForegroundColor 属性实现 Excel 单元格的背景色设置,FillP ...
- VS 文件共享
按照这个顺序:选中项目,鼠标右键菜单==〉添加==〉添加现有项==〉选择相应的文件==〉添加为链接注意,最后一步,添加按钮上有一个表示下拉的小三角,点击它就能看到“添加为链接”选项了.用的是VS201 ...