PYQT5连接按钮按下堆叠widget
我只是将.UI文件转换为PY文件,并尝试使用信号和插槽系统将QPUSHBUTTON
链接到QSTACKEDWIDGET
。这就是我尝试做的事情:
self.createButton.clicked.connect(self.stackedWidget.setCurrentIndex(2))
应该将堆叠的小部件的索引设置为2个按钮。但是,在运行时发生以下错误:
TypeError: argument 1 has unexpected type 'NoneType'
不确定是什么参数1,但是占位符的代码:
self.createButton.clicked.connect(self.stackedWidget.update)
似乎有效,除了我想实现的目标不是。我的代码怎么了?
I just converted my .ui file into the py file and tried to link a QPushButton
to a QStackedWidget
using the signals and slots system. This is what I attempted to do:
self.createButton.clicked.connect(self.stackedWidget.setCurrentIndex(2))
and it was supposed to set the index of the stacked widget to 2 on button click. However at runtime the following error occurred:
TypeError: argument 1 has unexpected type 'NoneType'
Was not really sure what argument 1 was, but the placeholder code of:
self.createButton.clicked.connect(self.stackedWidget.update)
seemed to work except that was not what I want to achieve. What is wrong with my code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当启用点击事件时,连接函数将作为参数作为一个函数要调用,因此您应该将statment包裹在lambda函数中,如下所示:
the the connect function takes as a parameter a function to call when the click event is emited so you should wrap your statment in a lambda function as follows :