PyQt 类型错误 connect() [英] PyQt TypeError connect()

查看:35
本文介绍了PyQt 类型错误 connect()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 Python 非常陌生,所以如果这是一个简单的错误,我很抱歉.

I'm very new to Python, so I'm sorry ahead of time if this is a simple mistake.

class TaskTabs(QtGui.QTabWidget):
    ...(some init stuff here)....
    def remove(self):
        self.removeTab(0)
        self.addTab(Tabs.General(self.nao, self.parent), 'General')

在另一个班级:

self.taskTabs = TaskTabs(self.nao, mainWidget)
....(Some other stuff here)....
loadEmpathy = QtGui.QAction(QtGui.QIcon(), '&Load Empathy', self)
loadEmpathy.setShortcut('Ctrl+E')
loadEmpathy.triggered.connect(self.taskTabs.remove())

我得到的错误是:

TypeError: connect() slot argument should be a callable or a signal, not 'NoneType'

我想要做的是从我的 GUI 中删除一个选项卡并从菜单中添加各种选项卡(我稍后会实现,现在只是测试一下).我的菜单代码运行良好,现在我想为单击它时发生的事情设置一个操作.我在我的 TaskedTabs 文件中创建了这个 remove 方法,remove 函数在我的 init 函数中工作得很好,但我想把它分开(为了以后的目的).谁能解释一下我的代码有什么问题?

What I am trying to do is to remove a tab in my GUI and add in various ones (which I'll implement later, just testing this now) from a menu. My menu code works perfectly, and now I want to set an action for what happens when it's clicked. I created this remove method in my TaskedTabs file, the remove function works great in my init function, but I want to separate it (for purposes later on). Can anyone explain what is wrong with my code?

推荐答案

正如错误信息所说,connect() 需要一个可调用的方法.但是你给它的是一个方法的结果,因为你正在调用它.remove() 返回 None,然后将其用作 connect() 的参数,这不起作用.通过删除 remove 之后的括号来解决这个问题.

As the error message says, connect() needs a callable method. But what you are giving it is the result of a method, because you're calling it. remove() returns None, which is then used as the argument for connect(), which doesn't work. Solve this by removing the brackets after remove.

loadEmpathy.triggered.connect(self.taskTabs.remove)

这篇关于PyQt 类型错误 connect()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆