代码之家  ›  专栏  ›  技术社区  ›  abhi krishnan

3秒后隐藏帧/通过调用函数(需要以两种方式完成)

  •  3
  • abhi krishnan  · 技术社区  · 6 年前

    我在同一个窗口中创建了两个帧,其中包含一些属性。现在我可以单独调用它,也可以同时显示两者

    from PyQt4 import QtCore, QtGui
    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_Dialog(object):
        def frame1(self,Dialog):
            self.frame = QtGui.QFrame(Dialog)
            self.frame.setGeometry(QtCore.QRect(40, 20, 311, 391))
            self.frame.setFrameShape(QtGui.QFrame.StyledPanel)
            self.frame.setFrameShadow(QtGui.QFrame.Raised)
            self.frame.setObjectName(_fromUtf8("frame"))
            self.label = QtGui.QLabel(self.frame)
            self.label.setGeometry(QtCore.QRect(120, 180, 72, 23))
            self.label.setObjectName(_fromUtf8("label"))
            self.label.setText(_translate("Dialog", "omniOS", None))
    
        def frame2(self,Dialog):
            self.frame_2 = QtGui.QFrame(Dialog)
            self.frame_2.setGeometry(QtCore.QRect(30, 30, 311, 391))
            self.frame_2.setFrameShape(QtGui.QFrame.StyledPanel)
            self.frame_2.setFrameShadow(QtGui.QFrame.Raised)
            self.frame_2.setObjectName(_fromUtf8("frame_2"))
            self.label_2 = QtGui.QLabel(self.frame_2)
            self.label_2.setGeometry(QtCore.QRect(50, 230, 72, 31))
            self.label_2.setObjectName(_fromUtf8("label_2"))
            self.lineEdit = QtGui.QLineEdit(self.frame_2)
            self.lineEdit.setGeometry(QtCore.QRect(150, 230, 113, 33))
            self.lineEdit.setObjectName(_fromUtf8("lineEdit"))
            self.label_2.setText(_translate("Dialog", "Login", None))
    
    
        def setupUi(self, Dialog):
            Dialog.setObjectName(_fromUtf8("Dialog"))
            Dialog.resize(391, 437)
            self.retranslateUi(Dialog)
            QtCore.QMetaObject.connectSlotsByName(Dialog)
    
        def retranslateUi(self, Dialog):
            Dialog.setWindowTitle(_translate("Dialog", "OmniOS", None))
            self.frame1(Dialog)
            self.frame2(Dialog)
    
    if __name__=="__main__":
        ui=Ui_Dialog()
        import sys
        a = QtGui.QApplication(sys.argv)
        w = QtGui.QWidget()
        ui.setupUi(w)
        w.show()
    
        sys.exit(a.exec_())
    

    我需要做的是,我需要在3秒钟后得到第一个窗口我需要得到第二个窗口+隐藏第一个窗口而不重叠它

     self.frame1(Dialog) # call this when the program start
     self.frame2(Dialog) # call this after 3 second self.frame1(Dialog) 
    

    1 回复  |  直到 6 年前
        1
  •  2
  •   eyllanesc RAHUL KUMAR    6 年前

    一个代码工作并不意味着它是正确的,例如,我看到你已经组合了两个由Qt设计器生成的代码,显然它们将重叠,正确的事情是有两个窗口,如下所示使用QTimer进行交换。

    from PyQt4 import QtCore, QtGui
    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_Dialog1(object):
        def setupUi(self, Dialog):
            self.frame = QtGui.QFrame(Dialog)
            self.frame.setGeometry(QtCore.QRect(40, 20, 311, 391))
            self.frame.setFrameShape(QtGui.QFrame.StyledPanel)
            self.frame.setFrameShadow(QtGui.QFrame.Raised)
            self.frame.setObjectName(_fromUtf8("frame"))
            self.label = QtGui.QLabel(self.frame)
            self.label.setGeometry(QtCore.QRect(120, 180, 72, 23))
            self.label.setObjectName(_fromUtf8("label"))
            self.label.setText(_translate("Dialog", "omniOS", None))
            Dialog.setObjectName(_fromUtf8("Dialog"))
            Dialog.resize(391, 437)
            self.retranslateUi(Dialog)
            QtCore.QMetaObject.connectSlotsByName(Dialog)
        def retranslateUi(self, Dialog):
            Dialog.setWindowTitle(_translate("Dialog", "OmniOS", None))
    
    
    class Ui_Dialog2(object):
        def setupUi(self, Dialog):
            self.frame_2 = QtGui.QFrame(Dialog)
            self.frame_2.setGeometry(QtCore.QRect(30, 30, 311, 391))
            self.frame_2.setFrameShape(QtGui.QFrame.StyledPanel)
            self.frame_2.setFrameShadow(QtGui.QFrame.Raised)
            self.frame_2.setObjectName(_fromUtf8("frame_2"))
            self.label_2 = QtGui.QLabel(self.frame_2)
            self.label_2.setGeometry(QtCore.QRect(50, 230, 72, 31))
            self.label_2.setObjectName(_fromUtf8("label_2"))
            self.lineEdit = QtGui.QLineEdit(self.frame_2)
            self.lineEdit.setGeometry(QtCore.QRect(150, 230, 113, 33))
            self.lineEdit.setObjectName(_fromUtf8("lineEdit"))
            self.label_2.setText(_translate("Dialog", "Login", None))
            Dialog.setObjectName(_fromUtf8("Dialog"))
            Dialog.resize(391, 437)
            self.retranslateUi(Dialog)
            QtCore.QMetaObject.connectSlotsByName(Dialog)
            self.retranslateUi(Dialog)
    
        def retranslateUi(self, Dialog):
            Dialog.setWindowTitle(_translate("Dialog", "OmniOS", None))
    
    
    class Dialog1(QtGui.QDialog, Ui_Dialog1):
        def __init__(self, parent=None):
            super(Dialog1, self).__init__(parent)
            self.setupUi(self)
    
    
    class Dialog2(QtGui.QDialog, Ui_Dialog2):
        def __init__(self, parent=None):
            super(Dialog2, self).__init__(parent)
            self.setupUi(self)
    
    
    
    if __name__=="__main__":
        import sys
        a = QtGui.QApplication(sys.argv)
        w1 = Dialog1()
        w2 = Dialog2()
    
        def on_timeout():
            w1.hide()
            w2.show()
    
        w1.show()
        QtCore.QTimer.singleShot(3000, on_timeout)
        sys.exit(a.exec_())