Design GUI interface in Python language

Source: Internet
Author: User

We have all written programs, but if you can design a GUI interface, it will add a great bright spot to the program! Today, let's write the most basic GUI in the very popular Python language and lay the groundwork for a more beautiful GUI later on. Tools/Materials
    • python compiler software
    • PYQT Design Software
Method/Step
  1. 1

    First, if you do not have Python and pyqt software installed, please search directly to download and install it first. Python is an open source software, so you can download it online for free, the latest version is available. Once the download is complete, we will open PYQT designer first.

  2. 2

    When opened, the first is a default new window interface, where we select the default window.

  3. 3

    Now is a completely blank window. The first step is to drag all the design elements into this window first. We first drag a "label", which is a non-editable label.

  4. 4

    We then dragged a "line edit" that we could edit.

  5. 5

    Finally we drag the last element: "Pushbutton" button, which is what we usually point to determine.

  6. 6

    We have now dragged all the required elements into the new window. For each element, we can double-click on the property value modification, at this point we just need to double-click to change the name to

  7. 7

    At this point we are halfway through, and then we need to operate on the action signal. We need to cut into the pattern of the edit signal first.

  8. 8

    When you move the mouse to any element, you will find it red, which means it is selected.

  9. 9

    When we select Pushbutton, continue to drag the mouse to the top of line edit, you will find an arrow pointing to the line edit by Pushbutton, the action on behalf of Pushbutton will be the operation of line edit.

  10. 10

    A Configuration Connection window will appear. On the left is the operation of Pushbutton, we choose clicked (), that is, click Pushbutton.

  11. On the right is the operation of line edit, we choose Clear (), that is, the contents of line edit.

  12. Finally we click OK.

  13. After the save is complete, our operation in PYQT is complete. The saved file name we named TEST,PYQT the resulting design file suffix is. UI.

  14. Then we need to convert the. ui file into a compiled. py file, and we need to use the PYUIC4 command provided by PYQT to complete the conversion. This is a DOS command, so we need to bring up the DOS interface. Open the Start menu and locate the run in the attachment.

  15. Enter CMD in the run and then open the DOS interface when you are sure.

  16. In the DOS interface, we need to navigate to the location of the. ui file that you just saved, and if it is the default, it will be saved in the C:\PYTHON27\LIB\SITE-PACKAGES\PYQT4, the location of the process. The command to convert to a. py file is: Pyuic4 test.ui-o test.py

  17. After the conversion command is executed, a test.py file is generated,

  18. Finally, we need to add a header file and a main function to the generated Python file, so we can generate a complete GUI program! The first is to add the import sys at the very beginning of the entire program.

  19. Also, at the end of the program, add the main function code. The main function calls the function that we have completed in the PYQT and configures the join function, so we just need to add the main function to call them.

  20. Once saved, double-click the python file that we edited, and the GUI interface we just designed will pop up! This is the first GUI program we have written in Python!

    END
Precautions
    • PYQT designed to complete the file is best saved in the default path, the path can be executed PYUIC4 conversion command, or the DOS system can not recognize pyuic4 this command.

Design GUI interface in Python language

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.