Hi all i'm new to python and qt

I have played a little with c++ and basic ,But most of the programing I have done in the past was for the web using java script, so this is all new to me.

I am working on a program, and would like to open a window when I push on a button. so fare every thing I have tried has failed. There really doesn't seem to be a good tutorial on this, so I was hoping some would post a simple example of how this is done.

To help with this I have posted three files two are the window files the last one is starting point for the program.

I think other newbies will find this interesting

Thanks for any help



Saved as "openwindowmain.py"
Qt Code:
  1. # -*- coding: utf-8 -*-
  2.  
  3. # Form implementation generated from reading ui file 'openwindowmain.ui'
  4. #
  5. # Created: Sun Feb 21 18:59:44 2010
  6. # by: PyQt4 UI code generator 4.3.3
  7. #
  8. # WARNING! All changes made in this file will be lost!
  9.  
  10. from PyQt4 import QtCore, QtGui
  11.  
  12. class Ui_Dialog(object):
  13. def setupUi(self, Dialog):
  14. Dialog.setObjectName("Dialog")
  15. Dialog.resize(QtCore.QSize(QtCore.QRect(0,0,268,184).size()).expandedTo(Dialog.minimumSizeHint()))
  16.  
  17. self.pushButton = QtGui.QPushButton(Dialog)
  18. self.pushButton.setGeometry(QtCore.QRect(60,60,161,61))
  19. self.pushButton.setObjectName("pushButton")
  20.  
  21. self.retranslateUi(Dialog)
  22. QtCore.QMetaObject.connectSlotsByName(Dialog)
  23.  
  24. def retranslateUi(self, Dialog):
  25. Dialog.setWindowTitle(QtGui.QApplication.translate("Dialog", "Dialog", None, QtGui.QApplication.UnicodeUTF8))
  26. self.pushButton.setText(QtGui.QApplication.translate("Dialog", "open window", None, QtGui.QApplication.UnicodeUTF8))
To copy to clipboard, switch view to plain text mode 


Saved as "openwindowchild.py"
Qt Code:
  1. # -*- coding: utf-8 -*-
  2.  
  3. # Form implementation generated from reading ui file 'openwindowchild.ui'
  4. #
  5. # Created: Sat Feb 27 13:49:23 2010
  6. # by: PyQt4 UI code generator 4.3.3
  7. #
  8. # WARNING! All changes made in this file will be lost!
  9.  
  10. from PyQt4 import QtCore, QtGui
  11.  
  12. class Ui_Dialog(object):
  13. def setupUi(self, Dialog):
  14. Dialog.setObjectName("Dialog")
  15. Dialog.resize(QtCore.QSize(QtCore.QRect(0,0,203,227).size()).expandedTo(Dialog.minimumSizeHint()))
  16.  
  17. self.label = QtGui.QLabel(Dialog)
  18. self.label.setGeometry(QtCore.QRect(50,70,131,51))
  19. self.label.setObjectName("label")
  20.  
  21. self.pushButton = QtGui.QPushButton(Dialog)
  22. self.pushButton.setGeometry(QtCore.QRect(40,160,141,51))
  23. self.pushButton.setObjectName("pushButton")
  24.  
  25. self.retranslateUi(Dialog)
  26. QtCore.QMetaObject.connectSlotsByName(Dialog)
  27.  
  28. def retranslateUi(self, Dialog):
  29. Dialog.setWindowTitle(QtGui.QApplication.translate("Dialog", "Dialog", None, QtGui.QApplication.UnicodeUTF8))
  30. self.label.setText(QtGui.QApplication.translate("Dialog", "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
  31. "p, li { white-space: pre-wrap; }\n"
  32. "</style></head><body style=\" font-family:\'Sans Serif\'; font-size:9pt; font-weight:400; font-style:normal;\">\n"
  33. "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:25pt; color:#ff7f50;\">Worked</span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8))
  34. self.pushButton.setText(QtGui.QApplication.translate("Dialog", "Close", None, QtGui.QApplication.UnicodeUTF8))
To copy to clipboard, switch view to plain text mode 


saved as "openwindow.py"
Qt Code:
  1. import sys
  2. from PyQt4 import QtCore, QtGui
  3. from openwindowmain import Ui_Dialog
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13. class StartQT4(QtGui.QMainWindow):
  14. def __init__(self, parent=None):
  15. QtGui.QWidget.__init__(self, parent)
  16. self.ui = Ui_Dialog()
  17. self.ui.setupUi(self)
  18. QtCore.QObject.connect(self.ui.pushButton,QtCore.SIGNAL("clicked()"), self.text_handler)
  19.  
  20.  
  21.  
  22.  
  23. def text_handler(self):
  24. print "worked"
  25.  
  26.  
  27.  
  28.  
  29.  
  30. if __name__ == "__main__":
  31.  
  32. app = QtGui.QApplication(sys.argv)
  33. myapp = StartQT4()
  34. myapp.show()
  35. sys.exit(app.exec_())
To copy to clipboard, switch view to plain text mode