莫回无
void QTimer::singleShot(int msec, const QObject *receiver, const char *member)这个静态函数在给定的时间间隔后调用一个槽。尝试一下:import sysfrom PyQt5.QtCore import *from PyQt5.QtGui import *from PyQt5.QtWidgets import *class stackedExample(QWidget): def __init__(self): super(stackedExample, self).__init__() self.leftlist = QListWidget() self.leftlist.insertItem (0, 'Contact' ) self.leftlist.insertItem (1, 'Personal' ) self.leftlist.insertItem (2, 'Educational' ) self.stack1 = QWidget() self.stack2 = QWidget() self.stack3 = QWidget() self.stack1UI() self.stack2UI() self.stack3UI() self.stackWidget = QStackedWidget(self) self.stackWidget.addWidget(self.stack1) self.stackWidget.addWidget(self.stack2) self.stackWidget.addWidget(self.stack3) hbox = QHBoxLayout(self) hbox.addWidget(self.leftlist) hbox.addWidget(self.stackWidget) self.setLayout(hbox) self.leftlist.currentRowChanged.connect(self.display) self.setGeometry(300, 50, 10, 10) self.setWindowTitle('StackedWidget demo') self.stackWidget.setCurrentIndex(0) QTimer.singleShot(3000, lambda: self.display(1)) QTimer.singleShot(6000, lambda: self.display(2)) QTimer.singleShot(9000, lambda: self.display(0)) self.show() def stack1UI(self): layout = QFormLayout() layout.addRow("Name", QLineEdit()) layout.addRow("Address", QLineEdit()) #self.setTabText(0,"Contact Details") self.stack1.setLayout(layout) def stack2UI(self): layout = QFormLayout() sex = QHBoxLayout() sex.addWidget(QRadioButton("Male")) sex.addWidget(QRadioButton("Female")) layout.addRow(QLabel("Sex"),sex) layout.addRow("Date of Birth",QLineEdit()) self.stack2.setLayout(layout) def stack3UI(self): layout = QHBoxLayout() layout.addWidget(QLabel("subjects")) layout.addWidget(QCheckBox("Physics")) layout.addWidget(QCheckBox("Maths")) self.stack3.setLayout(layout) def display(self, i): self.stackWidget.setCurrentIndex(i)def main(): app = QApplication(sys.argv) ex = stackedExample() sys.exit(app.exec_()) if __name__ == '__main__': main()