How to connect a QPushButton to a function
<p>I want to create a simple program with a PyQt GUI. For this I used Qt Designer, and I made a window with a push-button named <code>OpenImage</code>. Moreover, I have a file named <em>rony.py</em> that has a function <code>show</code>. So I want that when the user clicks the button, the image will appear.</p>

<p>This is my code:</p>

<pre><code>from PyQt4 import QtCore, QtGui
import rony

try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    def _fromUtf8(s):
        return s

try:
    _encoding = QtGui.QApplication.UnicodeUTF8
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig)

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName(_fromUtf8("MainWindow"))
        MainWindow.resize(800, 600)
        self.centralwidget = QtGui.QWidget(MainWindow)
        self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
        self.horizontalLayout = QtGui.QHBoxLayout(self.centralwidget)
        self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
        self.OpenImage = QtGui.QPushButton(self.centralwidget)
        self.OpenImage.setObjectName(_fromUtf8("OpenImage"))
        self.horizontalLayout.addWidget(self.OpenImage)
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtGui.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 21))
        self.menubar.setObjectName(_fromUtf8("menubar"))
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtGui.QStatusBar(MainWindow)
        self.statusbar.setObjectName(_fromUtf8("statusbar"))
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow", None))
        self.OpenImage.setText(_translate("MainWindow", "PushButton", None))


OpenImage.connect(show()) # Why this line don't work


if __name__ == "__main__":
    import sys
    app = QtGui.QApplication(sys.argv)
    MainWindow = QtGui.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())
</code></pre>

<p>rony.py</p>

<pre><code>from PIL import Image 
img = Image.open("pipe.png")

def show():
    img.show()
</code></pre>

<p>You have to reference the name of your script when calling a function from it. It works as a library:</p>

<pre><code>OpenImage.connect(rony.show())
</code></pre>

python pyqt signals-slots qpushbutton