Abid Rahman K Abid Rahman K - 1 year ago 109
Python Question

How to implement a simple button in PyQt

I want to implement a simple button in pyqt which prints "Hello world" when clicked. How can i do that?

I am a real newbie in PyQt. I am using fedora.

Thanks all

Answer Source

If you're new to PyQt4, there are some useful tutorials on the PyQt Wiki to get you started.

But in the meantime, here's your "Hello World" example:

from PyQt4 import QtGui, QtCore

class Window(QtGui.QWidget):
    def __init__(self):
        self.button = QtGui.QPushButton('Test', self)
        layout = QtGui.QVBoxLayout(self)

    def handleButton(self):
        print ('Hello World')

if __name__ == '__main__':

    import sys
    app = QtGui.QApplication(sys.argv)
    window = Window()
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download