我需要从login.py打开一个对话框,如果成功,对话框将关闭并从home.py打开一个主窗口。我需要使用 Qt Designer 使用 pyuic4 创建的文件来执行此操作。总之,我需要通过main.py调用login.py和home.py。
main.py的代码:
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_())
login.py的代码:
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName(_fromUtf8("Dialog"))
Dialog.resize(194, 156)
home.py的代码:
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName(_fromUtf8("MainWindow"))
MainWindow.resize(635, 396)
MainWindow.setAutoFillBackground(False)
更新: 感谢我的朋友;)使用此代码为我工作:
# -*- 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_()