0

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')

In another class:

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

There error that I am getting is:

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

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?

4

1 回答 1

2

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

loadEmpathy.triggered.connect(self.taskTabs.remove)
于 2013-05-22T16:16:08.077 回答