by

How to create a simple button in python using GUI PyQt4

Using PyQt4 python module, you can easily add a QtGui.QPushButton as interactive button in your mask.


Constructor QPushButton(string text, QWidget parent = None).

The 'text' parameter is the text displayed on the button. 

The 'parent' is a widget, onto which we place the button.

Thanks to http://zetcode.com/gui/pyqt4/firstprograms/
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/12154/How-to-create-a-simple-button-in-python-?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
#!/usr/bin/python import sys from PyQt4 import QtGui, QtCore class GUI_Example(QtGui.QWidget): def __init__(self): super(GUI_Example, self).__init__() self.initUI() def initUI(self): qbtn = QtGui.QPushButton('Quit', self) qbtn.clicked.connect(QtCore.QCoreApplication.instance().quit) qbtn.resize(qbtn.sizeHint()) qbtn.move(55, 55) self.setGeometry(300, 300, 250, 150) self.setWindowTitle('Quit button') self.show() def main(): app = QtGui.QApplication(sys.argv) ex = GUI_Example() sys.exit(app.exec_()) if __name__ == '__main__': main()

Other Steps and Solutions

If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus