我正在尝试构建一个应用程序并拥有一个向导。我已经用 pyqt5 创建了 GUI,并使用了 Qwizard 库作为向导。我试图将 qwizard 页面中的方法连接到 Next 按钮,但似乎找不到方法。
我希望连接类 page2 中称为 Next button 的方法,我希望在单击此页面上的下一个按钮时触发某些东西。
我的代码:
import sys
from PyQt5.QtWidgets import QWidget, QApplication, QToolBar, QAction, QVBoxLayout, QHBoxLayout, QGridLayout, QLabel,\
QGroupBox, QWizard, QWizardPage, QPushButton, QLineEdit, QComboBox
import PyQt5.QtGui as QtGui
from PyQt5.QtGui import QFont
class App(QWidget):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.left = 200
self.top = 200
self.width = 640
self.height = 480
self.title = "App"
self.setWindowTitle(self.title)
self.setWindowIcon(QtGui.QIcon("logo.ico"))
self.setGeometry(self.left, self.top, self.width, self.height)
self.toolbar = QToolBar("")
########################## ToolbarButtons ###################################
self.button_add = QAction("Add", self)
self.button_add.setIcon(QtGui.QIcon("add.ico"))
self.button_add.setStatusTip("Add stuff")
self.toolbar.addAction(self.button_add)
self.button_browse = QAction("Open", self)
self.button_browse.setIcon(QtGui.QIcon("folder.ico"))
self.button_browse.setStatusTip("Open stuff")
self.toolbar.addAction(self.button_browse)
self.button_save = QAction("Save", self)
self.button_save.setIcon(QtGui.QIcon("save.ico"))
self.button_save.setStatusTip("Save stuff")
self.toolbar.addAction(self.button_save)
self.button_settings = QAction("Settings", self)
self.button_settings.setIcon(QtGui.QIcon("settings.ico"))
self.button_settings.setStatusTip("Set stuff")
self.toolbar.addAction(self.button_settings)
self.window_layout = QGridLayout()
self.setLayout(self.window_layout)
self.wizard = WizardInit()
print("Test")
self.wizard.setWizardStyle(QWizard.ModernStyle)
self.show()
self.wizard.show()
class WizardInit(QWizard):
def __init__(self):
super().__init__()
self.setWindowTitle("Wizard")
self.resize(500, 500)
self.addPage(Page1())
self.addPage(Page2())
self.addPage(Page3())
class Page1(QWizardPage):
def __init__(self):
super().__init__()
class Page2(QWizardPage):
def __init__(self):
super().__init__()
def next_btn(self):
print("next")
class Page3(QWizardPage):
def __init__(self):
super().__init__()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = App()
sys.exit(app.exec_())