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'=>'确定要删除吗?']) ...
随机推荐
- Templates中的for标签
for 标签 {% for 变量 in 元组|列表|字典 %} {% endfor %} 在 Jinja2 模板的循环中,支持内部变量 - loop loop作用:记载当前循环中的一些相关信息 loo ...
- Vue.js学习使用心得(一)
一.初步了解 Vue.js是一套构建用户界面的渐进式框架,它只关注视图层, 采用自底向上增量开发的设计. Vue 的目标是通过尽可能简单的 API 实现响应的数据绑定和组合的视图组件,相当于JavaS ...
- PAT-7-14 电话聊天狂人
ps: 真不明白为什么水题不能一次ac 7-14 电话聊天狂人(25 分) 给定大量手机用户通话记录,找出其中通话次数最多的聊天狂人. 输入格式: 输入首先给出正整数N(≤105),为通话记录条 ...
- Codeforces 766C:Mahmoud and a Message(DP)
题目链接:http://codeforces.com/problemset/problem/766/C 题意 有一个长度为n的字符串,第二行有26个数字,位置1~26对应为a~z的字母,数值表示该字母 ...
- acm 2044
////////////////////////////////////////////////////////////////////////////////#include<iostream ...
- 【BZOJ3244】【UOJ#122】【NOI2013]树的计数
NOI都是酱的题怎么玩啊,哇.jpg 原题: 我们知道一棵有根树可以进行深度优先遍历(DFS)以及广度优先遍历(BFS)来生成这棵树的DFS序以及BFS序.两棵不同的树的DFS序有可能相同,并且它们的 ...
- 【BZOJ1492】【NOI2007】货币兑换
我果然不会斜率优化 原题: 小Y最近在一家金券交易所工作.该金券交易所只发行交易两种金券:A纪念券(以下简称A券)和 B纪念券(以下 简称B券).每个持有金券的顾客都有一个自己的帐户.金券的数目可以是 ...
- nginx启动重启与升级以及检测配置文件
查看nginx的主进程号 ps -ef|grep nginx 从容停止nginx kill - QUIT nginx主进程号 或者 kill - QUIT nginx的pid文件所在,例如我的 [ro ...
- centos7/linux 磁盘管理入门
添加新磁盘并挂载: 设置虚拟机系统里添加磁盘,重启虚拟机后,虚拟机目录/dev下会增加一个sdb设备. 使用fdisk /dev/sdb 管理磁盘分区,首先p 查看磁盘分区信息,然后n增加一个主分区, ...
- oracle-srvctl-output
############################## [grid@rac01 ~]$ crsctl query crs administratorCRS Administrator List: ...