简体   繁体   English

PyQt4:无法一次打开2个gui窗口

[英]PyQt4:Unable to open 2 gui windows at a time

import sys
from PyQt4 import QtCore, QtGui
from test_ui import Ui_MainWindow

class StartQt4(QtGui.QMainWindow):
    def __init__(self,parent=None):
        QtGui.QWidget.__init__(self)
        self.ui=Ui_MainWindow()
        self.ui2=Ui_MainWindow()
        self.ui2.setupUi(self)      # ui2 setup
        self.ui.setupUi(self)       # ui  setup .interchanging these 2 lines gives 2 guis


        QtCore.QObject.connect(self.ui.button_open,QtCore.SIGNAL("clicked()"),self.file_open)

    def file_open(self):
        self.ui.editor_window.setText('Yes u are doing good')

if __name__ == "__main__":
    app=QtGui.QApplication(sys.argv)
    myapp=StartQt4()
    myapp.show()
    sys.exit(app.exec_())

Trying to create simple pyqt4 gui.My goal is to open two gui windows at a time and hence created 2 objects ui ui2 .By swapping the lines that are commented,it works just fine,2 windows get opened.But when i leave it like this, only the ui object window get opened.How is that possible.They are just methods which are called at different times before displaying( myapp.show() ) right? 试图创建简单的pyqt4 gui。我的目标是一次打开两个gui窗口,因此创建了2个对象ui ui2 。通过交换评论的行,它工作正常,2个窗口打开。但是当我离开它时这个,只有ui对象窗口被打开。怎么可能。他们只是在显示之前在不同时间调用的方法( myapp.show() )对吗? Just started learning pyqt4. 刚开始学习pyqt4。

The generated class Ui_MainWindow doesn't represent the window itself, only the widgets contained in it. 生成的类Ui_MainWindow不代表窗口本身,只代表其中包含的小部件。 The window is the self parameter that you pass to setupUi() . 该窗口是您传递给setupUi()self参数。

To have 2 windows, you need to create 2 StartQt4 objects, each with only 1 Ui_MainWindow , and call show() for each of them. 要拥有2个窗口,您需要创建2个StartQt4对象,每个对象只有1个Ui_MainWindow ,并为每个对象调用show()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM