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'=>'确定要删除吗?']) ...
随机推荐
- JS中数据类型的判断
typeof 使用 : var n = "hello"; console.log(typeof n); console.log(typeof(n));
- 手机端touch事件封装
var touchEvent={ /*单次触摸事件*/ tap:function(element,fn){ var startTx, startTy; element.addEventListener ...
- webservice------UDDI SOAP WSDL 之间的关系
[ 真的是服了一些博客.....啰里啰唆的将一堆== 根本不知道讲的是什么 ... 在描述一个定义之前 (不如先通俗的讲它是干什么的)] SOAP(Simple Object Access P ...
- java poi解析excel报错处理
org.apache.xmlbeans.SchemaTypeLoaderException: XML-BEANS compiled schema: Incompatible minor version ...
- libsvm使用总结
./tools/ subset.py 分割数据集 grid.py 优化参数c.g checkdata.py 检测数据集格式 easy.py 综合 ./windows/ svm-scale ...
- hdu3605 Escape 二分图多重匹配/最大流
2012 If this is the end of the world how to do? I do not know how. But now scientists have found tha ...
- 【HAOI2011】problem b
数论好劲啊 原题: 对于给出的n个询问,每次求有多少个数对(x,y),满足a≤x≤b,c≤y≤d,且gcd(x,y) = k,gcd(x,y)函数为x和y的最大公约数. 1≤n≤50000,1≤a≤b ...
- nginx 优化(突破十万并发)
一般来说nginx配置文件中对优化比较有作用的为以下几项: worker_processes 8; nginx进程数,建议按照cpu数目来指定,一般为它的倍数. worker_cpu_affinity ...
- oracle使用一条语句批量插入多条数据
例如我有一个test表 create table (stuid int,name varchar(20); 插入多条数据,注意不能直接使用insert into test values(1,'a'), ...
- 使用uflare/smtp2http 将smtp 转转化为http 请求
uflare/smtp2http 是一个很不错的工具,我们使用这个工具,可以快速的将smtp 服务转换为http 服务 用途实际上挺多的 devops 系统 需要使用smtp的系统(测试) 基于smt ...