title: How do I close a window in PyQT when opening a new one?
body: <p>I am trying to create something, for school. I am using PyQT and QtDesigner. I was unaware that I wasn't supposed to edit the PYUIC4 generated code. Is there a way to close the window when opening a new window?
  Any help would be much appreciated, thanks:</p>
  
  <pre><code>from PyQt4 import QtCore, QtGui
  from medLogin import *
  import webbrowser
  import time
  
  try:
      _fromUtf8 = QtCore.QString.fromUtf8
  except AttributeError:
      def _fromUtf8(s):
          return s
  
  try:
      _encoding = QtGui.QApplication.UnicodeUTF8
      def _translate(context, text, disambig):
          return QtGui.QApplication.translate(context, text, disambig, _encoding)
  except AttributeError:
      def _translate(context, text, disambig):
          return QtGui.QApplication.translate(context, text, disambig)
  
  class Ui_titleMain(object):
      class openUiMain(object):
          def openLogin(self):
              print("Opening Login...")
              self.openLogin = QtGui.QMainWindow()
              self.ui = Ui_loginMainWin()
              self.ui.setupUi(self.openLogin)
              self.openLogin.show()
  
  
          def quitProgram(self):
              print("Program terminating...")
              time.sleep(0.5)
              quit()
  
          def openVleSite(self):
              print("Opening VLE Revision page.")
              time.sleep(0.5)
              webbrowser.open("")
              webbrowser.open("")
  
          def setupUi(self, titleMain):
              titleMain.setObjectName(_fromUtf8("titleMain"))
              titleMain.resize(300, 470)
              titleMain.setMinimumSize(QtCore.QSize(300, 470))
              titleMain.setMaximumSize(QtCore.QSize(300, 470))
              self.centralwidget = QtGui.QWidget(titleMain)
              self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
              self.mainTitle = QtGui.QLabel(self.centralwidget)
              self.mainTitle.setGeometry(QtCore.QRect(0, 10, 301, 141))
              self.mainTitle.setText(_fromUtf8(""))
              self.mainTitle.setPixmap(QtGui.QPixmap(_fromUtf8("C:\Users\Elliot\Desktop\m\logo1.jpg")))
              self.mainTitle.setAlignment(QtCore.Qt.AlignCenter)
              self.mainTitle.setObjectName(_fromUtf8("mainTitle"))
              self.bottomHorzLine = QtGui.QFrame(self.centralwidget)
              self.bottomHorzLine.setGeometry(QtCore.QRect(0, 150, 301, 16))
              self.bottomHorzLine.setFrameShape(QtGui.QFrame.HLine)
              self.bottomHorzLine.setFrameShadow(QtGui.QFrame.Sunken)
              self.bottomHorzLine.setObjectName(_fromUtf8("bottomHorzLine"))
              self.topHorzLine = QtGui.QFrame(self.centralwidget)
              self.topHorzLine.setGeometry(QtCore.QRect(0, 0, 301, 16))
              self.topHorzLine.setFrameShape(QtGui.QFrame.HLine)
              self.topHorzLine.setFrameShadow(QtGui.QFrame.Sunken)
              self.topHorzLine.setObjectName(_fromUtf8("topHorzLine"))
              self.beginButton = QtGui.QPushButton(self.centralwidget)
              self.beginButton.setGeometry(QtCore.QRect(0, 330, 301, 28))
              self.beginButton.setObjectName(_fromUtf8("beginButton"))
              self.beginButton.clicked.connect(self.openLogin)
              self.vleMedRevButton = QtGui.QPushButton(self.centralwidget)
              self.vleMedRevButton.setGeometry(QtCore.QRect(0, 370, 301, 28))
              self.vleMedRevButton.setObjectName(_fromUtf8("vleMedRevButton"))
              self.vleMedRevButton.clicked.connect(self.openVleSite)
              self.quitButton = QtGui.QPushButton(self.centralwidget)
              self.quitButton.setGeometry(QtCore.QRect(0, 410, 301, 28))
              self.quitButton.setObjectName(_fromUtf8("quitButton"))
              self.quitButton.clicked.connect(self.quitProgram)
              self.secondTitle = QtGui.QLabel(self.centralwidget)
              self.secondTitle.setGeometry(QtCore.QRect(4, 160, 291, 151))
              self.secondTitle.setObjectName(_fromUtf8("secondTitle"))
              self.bottomHorzLine_2 = QtGui.QFrame(self.centralwidget)
              self.bottomHorzLine_2.setGeometry(QtCore.QRect(0, 310, 301, 16))
              self.bottomHorzLine_2.setFrameShape(QtGui.QFrame.HLine)
              self.bottomHorzLine_2.setFrameShadow(QtGui.QFrame.Sunken)
              self.bottomHorzLine_2.setObjectName(_fromUtf8("bottomHorzLine_2"))
              titleMain.setCentralWidget(self.centralwidget)
              self.menubar = QtGui.QMenuBar(titleMain)
              self.menubar.setGeometry(QtCore.QRect(0, 0, 300, 26))
              self.menubar.setObjectName(_fromUtf8("menubar"))
              self.menuMenu = QtGui.QMenu(self.menubar)
              self.menuMenu.setObjectName(_fromUtf8("menuMenu"))
              titleMain.setMenuBar(self.menubar)
              self.actionVisit_VLE_Page = QtGui.QAction(titleMain)
              self.actionVisit_VLE_Page.setObjectName(_fromUtf8("actionVisit_VLE_Page"))
              self.actionVisit_VLE_Page.triggered.connect(self.openVleSite)
              self.actionQuit = QtGui.QAction(titleMain)
              self.actionQuit.setObjectName(_fromUtf8("actionQuit"))
              self.actionQuit.triggered.connect(self.quitProgram)
              self.menuMenu.addAction(self.actionVisit_VLE_Page)
              self.menuMenu.addAction(self.actionQuit)
              self.menubar.addAction(self.menuMenu.menuAction())
  
              self.retranslateUi(titleMain)
              QtCore.QMetaObject.connectSlotsByName(titleMain)
  
          def retranslateUi(self, titleMain):
              titleMain.setWindowTitle(_translate("titleMain", "Revision Program", None))
              self.beginButton.setText(_translate("titleMain", "Begin / Open menu", None))
              self.vleMedRevButton.setText(_translate("titleMain", "Visit  - Revision Page", None))
              self.quitButton.setText(_translate("titleMain", "Quit Program", None))
              self.secondTitle.setText(_translate("titleMain", "&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=\"center\"&gt;&lt;span style=\" font-size:12pt; font-weight:600;\"&gt;  Revision&lt;/span&gt;&lt;/p&gt;&lt;p align=\"center\"&gt;&lt;span style=\" font-size:12pt; font-weight:600;\"&gt;Program&lt;/span&gt;&lt;/p&gt;&lt;p align=\"center\"&gt;&lt;span style=\" font-size:10pt;\"&gt;Made with Python.&lt;br/&gt;Made to .&lt;/span&gt;&lt;/p&gt;&lt;p align=\"center\"&gt;&lt;span style=\" font-size:7pt; font-style:italic;\"&gt;Use the menu to choose your option.&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;", None))
              self.menuMenu.setTitle(_translate("titleMain", "Menu", None))
              self.actionVisit_VLE_Page.setText(_translate("titleMain", "Visit VLE Page", None))
              self.actionQuit.setText(_translate("titleMain", "Quit", None))
  
  if __name__ == "__main__":
      import sys
      app = QtGui.QApplication(sys.argv)
      titleMain = QtGui.QMainWindow()
      ui = Ui_titleMain.openUiMain()
      ui.setupUi(titleMain)
      titleMain.show()
      sys.exit(app.exec_())
  </code></pre>