Using Qt Designer files in python script
<p>I need to open a dialog from <em>login.py</em>, then if successful, the dialog will close and open a main-window from <em>home.py</em>. I need to do this with a file created by Qt Designer with pyuic4. In summary, I need to call <em>login.py</em> and <em>home.py</em> though <em>main.py</em>.</p>

<p>Code of <em>main.py</em>:</p>

<pre><code>from PyQt4 import QtGui, QtCore 
import sqlite3, time
from login import Ui_Dialog
from home import Ui_MainWindow

# Here I need to know how to call login.py, and
# after logged in, how to change to home.py

class RunApp():
    pass        

if __name__ == '__main__':

    app = QtGui.QApplication(sys.argv)
    window = RunApp()
    sys.exit(app.exec_())
</code></pre>

<p>Code of <em>login.py</em>:</p>

<pre><code>class Ui_Dialog(object):
    def setupUi(self, Dialog):
        Dialog.setObjectName(_fromUtf8("Dialog"))
        Dialog.resize(194, 156)
</code></pre>

<p>Code of <em>home.py</em>:</p>

<pre><code>class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName(_fromUtf8("MainWindow"))
        MainWindow.resize(635, 396)
        MainWindow.setAutoFillBackground(False)
</code></pre>

<p><strong>Update:</strong>
<strong>Thanks my friends ;) Worked for me with this code:</strong></p>

<pre><code># -*- coding: utf-8 -*-
from PyQt4 import QtGui, QtCore
from login import Ui_Dialog
from home import Ui_MainWindow
import sqlite3, time, sys, os

class MyLogin(QtGui.QDialog):
    def __init__(self):
        super().__init__()
        self.ui = Ui_Dialog()
        self.ui.setupUi(self)
        self.ui.buttonBox.accepted.connect(self.openHome)
    def openHome(self):
        ui2 = MyHome()
        ui2.show()
        ui2.exec_()


class MyHome(QtGui.QMainWindow):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.ui2 = Ui_MainWindow()
        self.ui2.setupUi(self)

if __name__=='__main__':
    root = QtGui.QApplication(sys.argv)
    app = MyLogin()
    app.show()
    root.exec_()
</code></pre>

<p>For login page of PyQt based application. i would suggest use <a href="http://pyqt.sourceforge.net/Docs/PyQt4/qstackedwidget.html" rel="nofollow">QstackedWidget</a></p>

<blockquote>
  <p>Page1 in stackedwidget for login page </p>
  
  <p>Page2 in stackwidget for home screen</p>
</blockquote>

<p>all you need is a simple login function that will varify the user name and password and allow user to move to home screen.</p>

<p>you can change the current index to open home screen.</p>

<pre><code>  self.stackedWidget.setCurrentIndex(1)
</code></pre>

python pyqt qt-designer pyuic