-1

pyqt でいくつかのページを作成し、それらを python で編集しました。

3 つのページがあると仮定し、このプログラムを 3 回実行する必要があります。「次へ」ボタンを使用して各ページを接続します。

ループしてみました。これがうまくいかなかった私のコードです。

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_())
4

1 に答える 1

1

コードに基づいて、積み重ねられたウィジェットでページを変更する方法の例を次に示します。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_())
于 2016-12-30T03:22:52.883 に答える