PyQt多窗口调用
经常有人问到如何在一个主窗口中打开一个对话框,然后在确认对话框之后,开启另一个窗口进行后续操作,
要求主窗口和最终的窗口之间都能响应用户操作,也就是非模态窗口。随手写了几行代码,简要示意。
:::python
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Gui (imgui@qq.com)
# License: BSD
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import sys
class W1(QWidget):
def __init__(self, parent=None):
super(W1, self).__init__(parent)
self.btn = QPushButton('Click1')
vb = QVBoxLayout()
vb.addWidget(self.btn)
self.setLayout(vb)
self.btn.clicked.connect(self.fireupWindows2)
def fireupWindows2(self):
w2 = W2()
if w2.exec_():
self.w3 = W3() # 需要通过self实例化为全局变量,不加self的话,一运行就被回收,也就无法显示。
self.w3.show()
class W2(QDialog):
def __init__(self, parent=None):
super(W2, self).__init__(parent)
self.btn = QPushButton('Click2')
vb = QVBoxLayout()
vb.addWidget(self.btn)
self.setLayout(vb)
self.btn.clicked.connect(self.fireupWindows3)
def fireupWindows3(self):
self.accept()
class W3(QWidget):
def __init__(self, parent=None):
super(W3, self).__init__(parent)
self.resize(300, 300)
self.btn = QLabel('The Last Window')
vb = QVBoxLayout()
vb.addWidget(self.btn)
self.setLayout(vb)
if __name__ == "__main__":
app = QApplication(sys.argv)
w = W1()
w.show()
sys.exit(app.exec_())
oneMainWindow.py
# -*- coding:utf-8 -*- from PyQt4.QtGui import (QMainWindow, QPushButton, QApplication,
QVBoxLayout, QWidget)
from PyQt4.QtCore import (Qt, QObject, SIGNAL)
import anotherWindow
import sys class OneWindow(QMainWindow):
def __init__(self):
super(OneWindow, self).__init__()
self.setGeometry(100, 100, 600, 400)
vLayout = QVBoxLayout()
self.button = QPushButton("OK")
vLayout.addWidget(self.button)
widget = QWidget()
widget.setLayout(vLayout)
self.setCentralWidget(widget)
QObject.connect(self.button,SIGNAL("clicked()") , self.anotherWindow)
def anotherWindow(self):
print 'OK'
self.another = anotherWindow.AnotherWindow()
self.another.show() #难道不是用这个show()函数吗?
if __name__ == '__main__':
app = QApplication(sys.argv)
w = OneWindow()
w.show()
app.exec_() anotherWindow.py
# -*- coding:utf-8 -*- from PyQt4.QtGui import (QMainWindow) class AnotherWindow(QMainWindow):
def __init__(self):
super(AnotherWindow, self).__init__()
self.resize(400, 300)
self.setWindowTitle("this is another window")
PyQt多窗口调用的更多相关文章
- 父窗口调用iframe子窗口方法
一.父窗口调用iframe子窗口方法 1.HTML语法:<iframe name="myFrame" src="child.html"></i ...
- 拥有iframe页面的子父类窗口调用JS的方法,并且注意的事项
一.前言 我页面用的是EasyUI的弹出窗口里面嵌入一个iframe.第一:父窗口打开子窗口是一个新增用户信息的iframe子页面,点击保存后,子窗口iframe则去调用父窗口的function cl ...
- pyqt pyside 窗口自动调整大小
pyqt pyside 窗口自动调整大小 在QTimer中一直调整 def initTimer(self): self.resizeTimer = QtCore.QTimer(self) self.r ...
- winform子窗口调用父窗口的控件及方法-一般调用
首先新建一个窗体应用程序,在项目属性中点击右键->添加->添加新项,选择Windows窗体->添加. 在Form1和Form2窗口中各添加一个按钮,并双击添加事件处理函数: ...
- 如何在pyqt中通过调用 SetWindowCompositionAttribute 实现Win10亚克力效果
亚克力效果 在<如何在pyqt中实现窗口磨砂效果>和<如何在pyqt中实现win10亚克力效果>中,我们调用C++ dll来实现窗口效果,这种方法要求电脑上必须装有MSVC.V ...
- JavaScript子窗口调用父窗口变量和函数的方法
在做一个父窗口开启子窗口并且在子窗口关闭的时候调用父窗口的方法,达到局部刷新的目的. 父窗口: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 ...
- javascript 之 location.href、跨窗口调用函数
location.href这个东西常常用于跳转,location既是window对象的属性,又是document对象的属性. JavaScript hash 属性 -- 返回URL中#符号后面的内容 ...
- window.open弹出窗口调用controller
前台图片调用js函数 <img src='${pageContext.request.contextPath}/FlatUI/img/link.png' id='report' alt='&qu ...
- 怎么在父窗口调用它页面的iframe里面数据,进行操作?
注:在服务器下操作有效果,本地无效 document.getElementById("taskdetail1").contentWindow.test(a) document.ge ...
随机推荐
- js中encode、decode的应用说明
escape 方法 返回一个可在所有计算机上读取的编码 String 对象. function escape(charString : String) : String 参数 charString 必 ...
- The Guide To Understanding mysqlreport
The Guide To Understanding mysqlreport This guide to understanding mysqlreport explains everything t ...
- Wireshark基本介绍和学习TCP三次握手(转)
http://www.cnblogs.com/TankXiao/archive/2012/10/10/2711777.html 之前写过一篇博客:用 Fiddler 来调试HTTP,HTTPS. 这篇 ...
- activiti学习资料(架构描述)
Activiti学习资料 Activiti是业界很流行的java工作流引擎,关于Activiti与JBPM5的关系和如何选择不是本文要讨论的话题,相关内容可以baidu一下.Activiti从架构角度 ...
- Python [Leetcode 342]Power of Four
题目描述: Given an integer (signed 32 bits), write a function to check whether it is a power of 4. Examp ...
- Heritrix源码分析(十四) 如何让Heritrix不间断的抓取(转)
欢迎加入Heritrix群(QQ):109148319,10447185 , Lucene/Solr群(QQ) : 118972724 本博客已迁移到本人独立博客: http://www.yun5u ...
- Microsoft Visual Studio 2010中文版编译SQLlite3.7.0版
作为一名教师,没有具体项目的开发,却喜欢尝鲜,不经意间开始追星了. 换了Win7,安装了Microsoft Visual Studio 2010中文版,7月22日SQLite发布了3.7.0版.当然想 ...
- [转] C# TextBox、DataGrideView中的数据绑定
Xavierr 原文 C#数据绑定——简单的文本框绑定.DataGridView 一.TextBox的数据绑定 经常写用一个TextBox显示某个对象,然后编辑之后再保存的程序.以前都是在TextBo ...
- C#调用WebService实现天气预报 http://www.webxml.com.cn
C#调用WebService实现天气预报 2011-02-21 14:24:06 标签:天气预报 休闲 WebServices 职场 C# 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始 ...
- Java并发编程-关卡
CyclicBarrier 直译过来叫循环栅栏,它主要的方法就是一个:await().await() 方法没被调用一次,计数便会减少1,并阻塞住当前线程.当计数减至0时,阻塞解除,所有在此 Cycli ...