by

How to create a simple GUI in python using PyQt4

In this example, we create a simple window using PyQt4 and its QtGui module.

Thanks to http://zetcode.com/gui/pyqt4/firstprograms/
post this code
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/12152/How-to-create-a-simple-GUI-in-python-usi?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 def main(): # Every PyQt4 application must create an application object. # The application object is located in the QtGui module. app = QtGui.QApplication(sys.argv) # The QWidget widget is the base class of all user interface objects in PyQt4. # We provide the default constructor for QWidget. The default constructor has no parent. # A widget with no parent is called a window. w = QtGui.QWidget() # The resize() method resizes the widget. w.resize(250, 150) w.move(300, 300) # Here we set the title for our window. w.setWindowTitle('Simple') # The show() method displays the widget on the screen. w.show() # Finally, we enter the mainloop of the application. 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