python changefig() takes exactly 2 arguments (1 given)
<p>I am writing a program which is supposed to give me data of a chart when i click certain buttons.
So this is the program as far as I am right now, I still have to connect the last 4 buttons but the first one works, but now there is another problem: I used to have a chart displayed as i clicked on "One Plot" but since I activated "First Button", the chart does not appear anymore due to the in the title mentioned problem. This is the script:</p>

<pre><code>class Main(QMainWindow, Ui_MainWindow):
def __init__(self, parent=None):
    super(Main, self).__init__(parent)
    self.setupUi(self)
    self.fig_dict = {}

    self.mplfigs.itemClicked.connect(self.changefig)


    self.button1.setText("First Point")
    self.button1.clicked.connect(self.onClickButton1)

    self.dialogbutton1 = PopUp(self)

    fig = Figure()
    self.addmpl(fig)
@QtCore.pyqtSlot()
def changefig(self, item):
    text = item.text()
    self.rmmpl()
    self.addmpl(self.fig_dict[str(text)])

def addfig(self, name, fig):
    self.fig_dict[name] = fig
    self.mplfigs.addItem(name)

def addmpl(self, fig):
    self.canvas = FigureCanvas(fig)
    self.mplvl.addWidget(self.canvas)
    self.canvas.draw()

    self.toolbar = NavigationToolbar(self.canvas, 
            self.mplwindow, coordinates=True)
    self.mplvl.addWidget(self.toolbar)

def onClickButton1(self):
    """ When button 1 is clicked I do the following """
    print "does nothing now."

    self.dialogbutton1.exec_()

def rmmpl(self,):
    self.mplvl.removeWidget(self.canvas)
    self.canvas.close()
    self.mplvl.removeWidget(self.toolbar)
    self.toolbar.close()
</code></pre>

<p>class PopUp(QtGui.QDialog):
    def <strong>init</strong>(self, parent=None):
        super(PopUp, self).<strong>init</strong>(parent)</p>

<pre><code>    self.buttonBox = QtGui.QDialogButtonBox(self)
    self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
    self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)

    self.textBrowser = QtGui.QTextBrowser(self)
    self.textBrowser.append("x - Coordinate = 0                                                                         y - Coordinate = 0.031451")

    self.verticalLayout = QtGui.QVBoxLayout(self)
    self.verticalLayout.addWidget(self.textBrowser)
    self.verticalLayout.addWidget(self.buttonBox)
</code></pre>

<p>if <strong>name</strong> == '<strong>main</strong>':
    import sys
    from PyQt4 import QtGui
    import numpy as np</p>

<pre><code>fig1 = Figure()
ax1f1 = fig1.add_subplot(111)
ax1f1.plot(np.random.rand(5))


app = QtGui.QApplication(sys.argv)
main = Main()
main.addfig('One plot', fig1)

print main.fig_dict
main.show()
sys.exit(app.exec_())
</code></pre>

<p>In <code>class Main</code>, you are calling <code>changefig</code> function as <code>self.mplfigs.itemClicked.connect(self.changefig)</code>.</p>

<p>But function definition of <code>changefig</code> is <code>def changefig(self, item):</code> which expects two arguments - <code>self</code> and <code>item</code>.</p>

<p>When you called changefig - <code>self.mplfigs.itemClicked.connect(self.changefig)</code>, only self is passed. But item is not passed. </p>

<p>That's why you are getting that error.</p>

<p>It should be <code>self.mplfigs.itemClicked.connect(self.changefig(item))</code></p>

python arguments