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'=>'确定要删除吗?']) ...
随机推荐
- [LeetCode&Python] Problem 100. Same Tree
Given two binary trees, write a function to check if they are the same or not. Two binary trees are ...
- MarkDown常用语法表
MarkDown常用语法表 本文提供全流程,中文翻译.Chinar坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) 1 Title - 标题 2 H ...
- 51Nod 1135:元根(数论)
1135 原根 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 收藏 关注 设m是正整数,a是整数,若a模m的阶等于φ(m),则称a为模m的一个原根.(其中φ(m) ...
- linux 用户配制文件 用户增加及删除 以及用户属于的更改
1.用户密码文件 /etc/passwd root : x : 0 : 0 : root : /root : / ...
- (10)MySQL触发器(同时操作两张表)
什么是触发器 触发器是与表有关的数据库对象,在满足定义条件时触发,并执行触发器中定义的语句集合.触发器的这种特性可以协助应用在数据库端确保数据的完整性. 举个例子,比如你现在有两个表[用户表]和[日志 ...
- [codeforces][Educational Codeforces Round 53 (Rated for Div. 2)D. Berland Fair]
http://codeforces.com/problemset/problem/1073/D 题目大意:有n个物品(n<2e5)围成一个圈,你有t(t<1e18)元,每次经过物品i,如果 ...
- struts2简单类型参数转换器(拦截器自动转换)
这边测试类型int,string,date,list(set),map,下面贴代码 struts.xml文件代码 <!-- 类型转换 --> <action name="C ...
- Java中的Graphics2D类基本使用教程
Java语言在Graphics类提供绘制各种基本的几何图形的基础上,扩展Graphics类提供一个Graphics2D类,它拥用更强大的二维图形处理能力,提供.坐标转换.颜色管理以及文字布局等更精确的 ...
- hostswap dcevm
什么是dcevm dcevm(DynamicCode Evolution Virtual Machine)是java hostspot的补丁(严格上来说是修改),允许(并非无限制)在运行环境下修改加载 ...
- redis使用问题总结
1.redis使用过多内存导致其他进程无法正常运行情况: 解决方案:限制redis的最大使用内存,修改redis.conf中的maxmemory(一般不要超过空闲内存的3/5,如果不设置ma ...