Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在python中的QStackedWidget中循环翻页?_Python_Pyqt_Qstackedwidget - Fatal编程技术网

如何在python中的QStackedWidget中循环翻页?

如何在python中的QStackedWidget中循环翻页?,python,pyqt,qstackedwidget,Python,Pyqt,Qstackedwidget,我用pyqt制作了一些页面,然后用python编辑它们 我假设有3个页面,我希望这个程序运行3次,也就是说从第1页到第2页到第3页到第1页。我使用“下一步”按钮连接每个页面 我试过了。这是我不起作用的代码 import sys from PyQt4.QtCore import * from PyQt4.QtGui import * from test import * app = QApplication(sys.argv) window = QMainWindow() ui = Ui_Mai

我用pyqt制作了一些页面,然后用python编辑它们

我假设有3个页面,我希望这个程序运行3次,也就是说从第1页到第2页到第3页到第1页。我使用“下一步”按钮连接每个页面

我试过了。这是我不起作用的代码

import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from test import *

app = QApplication(sys.argv)
window = QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(window)

for i in range(3):
  def find_page():
      ui.stackedWidget.childern()
   window.visible = ui.stackedWidget.currentIndex()

  def next():
      ui.stackedWidget.setCurrentIndex(ui.stackedWidget.currentIndex()+1)
      print(window.visible)
  ui.next.clicked.connect(next)
window.show()
sys.exit(app.exec_())

下面是一个基于代码的示例,介绍如何使用堆叠小部件更改页面。你没有发布你的UI文件,所以我不得不临时制作其他小部件。您必须更改PyQt4的导入,但其余内容应相同:

import sys

from PyQt5.QtCore import QTimer
from PyQt5.QtWidgets import QApplication, QLabel, QMainWindow, QStackedWidget

app = QApplication(sys.argv)

window = QMainWindow()
stack = QStackedWidget(parent=window)
label1 = QLabel('label1')
label2 = QLabel('label2')
label3 = QLabel('label3')
stack.addWidget(label1)
stack.addWidget(label2)
stack.addWidget(label3)
print('current', stack.currentIndex())
window.show()

def next():
      stack.setCurrentIndex(stack.currentIndex()+1)
      print('current', stack.currentIndex())

QTimer.singleShot(1000, next)
QTimer.singleShot(2000, next)
QTimer.singleShot(3000, next)
QTimer.singleShot(4000, app.quit)

sys.exit(app.exec_())

到底是什么不起作用?