Python GUI Tools-->pyqt4 Getting Started __python

Source: Internet
Author: User
Tags qt designer

If you want to use Python to develop a graphical interface, there are many tools to choose from, each with the pros and cons, previously used Wxpython+boa-constructor, has not been clear.

New understanding of the next PyQt4, seems to use this person also more, so decided to start learning this. Version:pyqt-py2.7-x86-gpl-4.9.1-1.exe

PyQt4 takes a QT designer and uses it to create an interface, layout controls such as Form,button,text, and so on, using the edit signal/slot pattern to define events.

Similar to C # creation form, but not as convenient as C #.


General steps:

1. Create GUI interface with designer, select template after startup, such as widget, drag some controls to interface, such as Button,text

2. Modify the control's name, text, title, and so on by the right property editor

3. Save as a. ui file, through the Pyuic4.bat tool under PYQT4, command line execution: Pyuic4.bat test.ui > ui_test.py generates a UI class file for the UI interface design

4. Then write the custom class and Main, and use the UI classes file import

5. Expand functionality by setting up your own slots (not yet researched)

PS:QT uses a mechanism called signal/slot (signals/slots) to pass events and messages between window artifacts (and other objects).

================================================================

# Simple Notepad, open (empty), close

Import Sys
From PYQT4 import Qtgui
From Ui_notepad import Ui_notepad


Class Mynotepad (Qtgui.qmainwindow):
'''
Classdocs
'''


def __init__ (Self,parent=none):
'''
Constructor
'''
qtgui.qwidget.__init__ (self,parent)
Self.ui = Ui_notepad ()
Self.ui.setupUi (self)



if __name__ = = ' __main__ ':
App = Qtgui.qapplication (SYS.ARGV) # * must
MyApp = Mynotepad () # *
Myapp.show ()
Sys.exit (App.exec_ ()) # *



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.