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? Just started learning pyqt4.
The generated class Ui_MainWindow
doesn't represent the window itself, only the widgets contained in it. The window is the self
parameter that you pass to setupUi()
.
To have 2 windows, you need to create 2 StartQt4
objects, each with only 1 Ui_MainWindow
, and call show()
for each of them.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.