Python _PyQt5对话框
Python 调用PyQt5 制作对话框,退出时候有二次确认(注:默认是直接退出)

1 # -*- ytf-8 -*-
2 """
3 用PyQt建一个对话框,退出时提示有二次确认
4 """
5
6 import sys
7 from PyQt5.QtWidgets import QApplication,QMessageBox,QWidget
8
9 class myWin(QWidget):
10 def __init__(self):
11 #执行父类的__init__构造方法
12 super().__init__()
13 #将窗口的设置委托给initUI方法
14 self.initUI()
15 def initUI(self):
16 #设置窗口
17 self.setWindowTitle("消息框")
18 self.setGeometry(200,200,500,500) #先位置再大小
19 self.show()
20 #重写关闭事件方法(closeEvent)
21 def closeEvent(self,event):
22 #获取消息框实例的值
23 msg = QMessageBox.question(self,"退出警告","你确定退出吗?",QMessageBox.Yes|QMessageBox.No,QMessageBox.No) #这里是固定格式,yes/no不能动
24 #判断消息的返回值
25 if msg ==QMessageBox.Yes:
26 event.accept()
27 else:
28 event.ignore()
29 if __name__=="__main__":
30 app=QApplication(sys.argv)
31 my=myWin()
32 sys.exit(app.exec_())
PyQt5_对话框_退出时确认
Python_menuBar

1 import sys
2 from PyQt5.QtWidgets import QApplication,QMainWindow,QAction,QMessageBox
3 from PyQt5.QtGui import QIcon
4
5 class myWin(QMainWindow):
6 def __init__(self):
7 super().__init__()
8 self.initUI()
9
10 def initUI(self):
11 #创建动作对象并设置
12 action_close=QAction(QIcon('icon.png'),'&退出',self)
13 action_close.setShortcut('A')
14 action_close.setStatusTip('这是退出功能')
15 action_close.triggered.connect(self.close)
16
17 action_open=QAction(QIcon('icon.png'),'&打开',self)
18 action_open.setShortcut('Ctrl+O')
19 action_open.setStatusTip('这是打开功能')
20 action_open.triggered.connect(self.open1)
21
22 #创建菜单
23 menuBar=self.menuBar()
24 menufile=menuBar.addMenu('&文件')
25 menufile.addAction(action_open)
26 menufile.addAction(action_close)
27
28 #设置状态栏
29 self.statusBar().showMessage('这个是状态栏....')
30
31 #设置窗口属性
32 self.setGeometry(100,300,400,400)
33 self.setWindowTitle('菜单栏实例')
34 self.setWindowIcon(QIcon('icon.png'))
35
36 self.show()
37 #重写关闭事件方法(closeEvent)
38 def closeEvent(self,event):
39 #获取消息框实例的值
40 msg=QMessageBox.question(self,'退出警告','你确认退出吗??',QMessageBox.Yes | QMessageBox.No,QMessageBox.No)
41 #判定消息框的返回值
42 if msg==QMessageBox.Yes:
43 event.accept()
44 else:
45 event.ignore()
46 def open1(self):
47 print('马季是个相声家')
48
49 if __name__=='__main__':
50 app=QApplication(sys.argv)
51 my=myWin()
52 sys.exit(app.exec_())
Python_menuBar

1 # -*- coding:utf-8 -*-
2
3 """
4 图形界面
5 拖动 只在图形界面
6
7
8 对于接收拖动组件:
9 1、开启 setAcceptDrops 允许接收拖动
10 2、重写 dragEnterEvent 对拖入数据进行过滤
11 3、重写 dropEvent 放入拖拽状态
12
13 对于拖出组件
14 设置setDragEnabled 为 True 允许拖动操作
15
16
17 目标:将单行文本框里的文字拖到按钮中,在按钮中显示
18 """
19
20 from PyQt5.QtWidgets import QApplication,QWidget,QLineEdit,QPushButton
21 import sys
22
23 #创建一个可以拖入的按键类型
24 class btn_drag(QPushButton):
25 #注意构造方法与按钮之间的参数的需求关系
26 def __init__(self,title,parent): #形参
27 super().__init__(title,parent)
28 self.setAcceptDrops(True) #允许拖入
29
30 def dragEnterEvent(self,e): #重写 拖拽进入方法
31 if e.mimeData().hasFormat("text/plain"): #过滤信息,只能是文本下的纯文本格式
32 e.accept()
33 else:
34 e.ignore()
35
36 def dropEvent(self,e): #重写放入事件
37 self.setText(e.mimeData().text()) #将拖入的文本信息放入到当前实例的text中
38
39 #新建基本框,有单行文本框和按钮
40 class myWin(QWidget):
41 def __init__(self):
42 super().__init__()
43 self.initUI()
44
45 def initUI(self):
46 btn=btn_drag("ok",self) #实例化框中按钮
47 edit=QLineEdit('000',self)
48 edit.setDragEnabled(True) #设置允许拖拽
49 btn.setGeometry(10,10,100,40)
50 edit.setGeometry(10,70,80,20)
51
52 self.setGeometry(150,150,500,300)
53 edit.setWindowTitle("拖拽实例1")
54 self.show()
55
56 if __name__ == "__main__":
57 app = QApplication(sys.argv)
58 my = myWin()
59 sys.exit(app.exec_())
PyQt5 拖动单行文本框的文字到一个按钮里

1 """
2 选择框
3 """
4
5 import sys
6 from PyQt5.QtWidgets import QApplication,QWidget,QComboBox #combox选择框
7
8 class myWin(QWidget):
9 def __init__(self):
10 super().__init__()
11 self.initUI()
12 def initUI(self):
13 self.com=QComboBox(self) #实例化选择框
14 self.com.setGeometry(40,40,100,20)
15 self.com.addItem("东")
16 self.com.addItem("南")
17 self.com.addItem("西")
18 self.com.addItem("北")
19
20 self.setGeometry(100,100,300,300)
21 self.setWindowTitle("选择框")
22 self.show()
23 def shows(self,date):
24 print(date)
25 self.lb1.setText(str(date))
26
27 if __name__=="__main__":
28 app = QApplication(sys.argv)
29 my = myWin()
30 sys.exit(app.exec_())
31
选择框
Python _PyQt5对话框的更多相关文章
- Python _PyQt5 【总】
http://www.cnblogs.com/archisama/p/5442071.html QtCore QtGui QtWidgets QtMultimedia QtBluetooth QtNe ...
- python :模态对话框
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...
- [Python] Remote debugging by Pycharm
From: http://blog.csdn.net/u013088062/article/details/50170551 虚拟环境配置 配置远程解释器 设想这样一种情况,你在一个平台上操作你的工程 ...
- [Python] Interpreter setting in Pycharm
From: http://blog.csdn.net/u013088062/article/details/50135135 From: http://blog.csdn.net/u013088062 ...
- [Python] Basic operations in Pycharm
From: http://learnpythonthehardway.org/book Comment with line comment: Ctrl + slash Run: Shift + F10 ...
- Python在windows下的安装与配置
安装python 文件准备: A. python安装文件:我用的是python-3.4.3.amd64.msi: 安装很简单,直接双击点下一步即可: 配置环境变量,在windows系统变量中找到pat ...
- Odoo 12 开发手册指南(八)—— 业务逻辑 – 业务流程的支持
在前面的文章中,我们学习了模型层.如何创建应用数据结构以及如何使用 ORM API 来存储查看数据.本文中我们将利用前面所学的模型和记录集知识实现应用中常用的业务逻辑模式. 本文的主要内容有: 以文件 ...
- 在cmd下可以import cv2,而Pycharm报错:找不到cv2
平台:win10 x64+Pycharm+Anaconda3+opencv 安装教程:参考博客——http://blog.sina.com.cn/s/blog_cca23c300102xiy4.htm ...
- [Pycharm] Interpreter setting in Pycharm
From: http://blog.csdn.net/u013088062/article/details/50135135 From: http://blog.csdn.net/u013088062 ...
随机推荐
- centos8上使用gitosis管理git项目
零,centos8平台如何安装gitosis服务? 参见:centos8平台安装gitosis服务 地址:https://www.cnblogs.com/architectforest/p/12456 ...
- selenium--数据填充
from time import sleep from selenium import webdriver br = webdriver.Chrome() url = "https://ww ...
- sql server 2008 r2 直接下载地址,可用迅雷下载
sqlserver 2008 r2 直接下载地址,可用迅雷下载 下载sqlserver 2008 r2 ,微软用了一个下载器,经过从下载器上,将他的地址全部用键盘敲了下来.最终的简体中文版地址如下: ...
- UVA 12298 Super Poker II (FFT)
#include<cstdio> #include<cmath> #include<cstring> #include<algorithm> using ...
- JAVA 基于Jusup爬虫
java爬虫核心:httpclient slf4j jsoup slf4j 配置文件log4j.properties log4j.rootlogger=DEBUG,A1log4j.logger.cn. ...
- C#语言下使用gRPC、protobuf(Google Protocol Buffers)实现文件传输
初识gRPC还是一位做JAVA的同事在项目中用到了它,为了C#的客户端程序和java的服务器程序进行通信和数据交换,当时还是对方编译成C#,我直接调用. 后来,自己下来做了C#版本gRPC编写,搜了很 ...
- html中的特殊字符表
- java前后端开发需掌握的框架及技术
一.Java开发 1.J2EE架构及主流框架,spring4.spring boot.spring MVC.spring Security.spring cloud.struct2.hibernate ...
- C#基础访问修饰符概述
前言: 在编写面向对象语言时我们时长离不开相关类型和成员的相关访问性,而访问性的关键则是取决于访问修饰符的声明,其作用是用于指定类型或成员的可访问性. 访问修饰符的六种可访问性级别: public:共 ...
- 从原生web组件到框架组件源码(二)
innerHTML outerHTML textContent innerText 区别 <div id="test"> <span>sdsdsdsd &l ...