程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Pyqt: using Python to create GUI interface applications like c++

編輯:Python

[ Here is the picture 001]

One 、 brief introduction

Python The standard library is more suitable for processing background tasks , Unique graphics library tkinter It's very inconvenient to use , So then came the idea of Python Graphical interface development extension library , Today the old ape is going to introduce the mainstream Python One of the GUI extension libraries PyQt.

Introducing PyQt Before , I have to give you a brief introduction Qt.Qt It's a C++ Visual development platform , It's a cross platform C++ GUI application framework (C++ GUI), It can provide application developers with the functions needed to build a graphical user interface .Qt Is completely object-oriented 、 Easy to expand , Can be applied to component programming , And can be used for embedded development . It's popular right now Linux Desktop Environment KDE The basis of , yes Linux And the mainstream GUI development environment under the embedded operating system , The biggest advantage is that you only need to write code once , Can be compiled and deployed on any operating system and hardware . Because I'm good at GUI development , Now it's extended to mobile and embedded device development . Great value for commercial software companies , It can be widely used in the Internet of things, especially in smart cars 、 R & D of intelligent manufacturing industry, etc .

PyQt It's a creation Python GUI Toolkit for applications , yes Qt and Python A product of the combination , It can be said that it is for the purpose of Qt The function of is used for Python One developed Qt Of Python Wrappers . It is Python Programming languages and Qt Successful integration of Libraries .

PyQt The whole program development framework of , The old ape thinks it mainly includes the following parts :

  • Graphical interface editing tools :Qt Designer
  • Different parts of the information exchange mechanism : Signals and slots
  • The event and capture mechanism of interface operation
  • A set of control interface display and data storage separation and mapping mechanism :Model/View framework

Through these important tools and framework mechanisms , Developers can design the corresponding GUI Graphical interface 、 Define the operation and response of different components 、 Capture the message of component or application and realize the linkage of interface display component and data storage component , So as to construct a complete application framework .

Two 、Qt Designer:PyQt Graphical interface development tool

Qt Designer It's a visual interface design tool , You can design the interface by dragging and dropping . The following is Qt Designer Operation interface of :

The old ape marked all parts of the interface with red numbers , According to the numerical order, the corresponding functions of each area are :

1、 Interface element control area

This section provides Qt All visual controls , Divided into eight categories , They are layout controls (Layouts)、 Separate controls (Spacers)、 Button control (Buttons)、 Item view (item views)、 Item component (item widgets)、 Containers (Containers)、 Input components (input widgets)、 According to the component (Display widgets), After creating a new window , You can drag and drop components of various functions onto the window to realize visual interface design .

2、 Menus and toolbars

This section is the operation menu and corresponding toolbar . among :
File The menu is used to create a new 、 open 、 Open recent 、 Save the interface UI file .
Edit Menu can edit interface control 、 Control properties 、 The signal / Slot connection 、 Control Tab The order 、 Tags and other controls, etc
Form The menu is used to edit the layout of the current window 、 size , Preview window, etc .
View The menu is to see which areas of the overall interface are displayed , In this paper, we divide UI Which areas of the design workspace are displayed on the interface ;
window The menu is the current UI Switch the design window .

3、UI Design workspace

all UI Design workspace , Workspace built UI Keep as design results .

4、 Component property definition area

This part completes the setting of each attribute of the component , Properties are classes by component 、 In the way of parent class , Due to too many properties, the single page is not displayed completely , This is not reflected in the screenshot above , If you collapse the parent nodes of these attributes , You can see the relationship very clearly , The following figure shows the collapse of the root node of the input control :

You can see , Except for the control itself QLineEdit Out of class , And the parent class QWidget、QObject, In this screenshot , These three are based on the parent class 、 Subclasses are shown in the following order , According to the old ape, it's mostly like this , But some special cases may not be like this . Here's the picture :

Above picture QTreeView Control and the nodes above it are displayed by parent-child inheritance , But there's more down there Header.
Through these displays of information , We can clearly know which attributes are brought from which class .

5、 The signal / Slot editing area

The signal and slot are Qt The most distinctive content , The details are introduced later , Here you can edit the connection between signal and slot function , But just press F4 It is more convenient to enter the interface of signal and slot function connection .

6、 Action editing area

action Action yes Qt Abstract user interface operations ,Qt An object introduced separately in , Corresponding QAction class .Action Represents a separate operation , It's a menu that can be used on the interface 、 Shortcut key 、toolBar The same operation performed by a button maps to the same Action object , The object triggers the actual operation through the signal .

3、 ... and 、PyQt The signal and slot of the three frame mechanisms

The signal and slot are PyQt and Qt Unique information transmission mechanism , yes PyQt and Qt An important foundation for designing programs , It allows objects that don't interfere with each other to establish a connection .

Signals and slots are used for communication between objects , In a GUI program , When changes occur in a component , You usually need to notify other objects , stay Qt When a specific event occurs, a signal is sent to notify the object that needs to be notified , The object that needs attention will call the slot function of the signal connection to perform the response operation . The signal is essentially a public function ( Or method ).

Slots can be used to receive signals , But slots are also normal member functions of a class derived from a part , Slots are essentially methods of a class ( Including virtual methods ), Used to call in response to a specific signal , Slot functions of non virtual functions can also be called normally , The only difference from ordinary examples is that signals can be connected to them .

Four 、PyQt The event mechanism of the three framework mechanisms

PyQt In the application of graphical interface , Event handling is similar to Windows Message processing of the system . When an application with a graphical interface starts , Event handling ( Such as mouse event handling 、 Keyboard event handling, etc ) It's the main loop of the application , Event handling is responsible for receiving events 、 Distribute events 、 Receive the return result of the application processing event , It's good to capture the events concerned by the application in the program and trigger related event processing UI The only way to develop .

PyQt The events in are divided into application level events 、 Component level events , All events can be captured and filtered , So as to affect the result of event processing .

5、 ... and 、PyQt One of the three framework mechanisms Model/View framework

stay PyQt and Qt in ,Model/View Architecture is used to manage the relationship between data and interface presentation in the development of graphical interface . The functional separation introduced by the architecture enables developers to customize the presentation of data items more flexibly , Standard model interface is provided to support a wide range of data sources and predefined item views (item views) Use it together .

The old ape understood Model/View Namely Model Provide data access ,View Data presentation , The two can be bound to achieve linkage , But the style of the interface presentation has nothing to do with the data itself .

6、 ... and 、 Some old apes use PyQt Do the case of interface

The old ape is a man without artistic cells , It's done GUI The interface is really ugly , But that's not to say PyQt Can't make a cool interface , On the contrary ,Qt or PyQt Can make beautiful interface .

The following is to illustrate PyQt There are many styles of interface, some old ape interface , For illustration only PyQt Types of interface styles that can be supported :

  • listView For file directory display

  • use QTableView Exhibition Excel file

  • use QTreeWidget Show directory file information

  • use QTableWidget Operation form

  • use QTabWidget The options window displays different operation pages

  • use QToolBox Built desktop toolbox

  • use QStackedWidget Build a stacked window to show multiple images

  • QMdiArea The multi document interface component displays multiple images at a time

  • QDockWidget Parking window ( For docking windows, see the bottom window toggle tab )
  • Use the main window QMainWindow An implementation of eliminating video Logo Tools for

    The interface design of the above cases is very good Low, Not at all PyQt The interface design function of is not good , I believe that people with artistic cells can design , It's 10000 times more beautiful than an old ape .

7、 ... and 、 Summary

This paper introduces Python Graphical interface application development tools PyQt The function and development framework of , adopt PyQt These important tools 、 Function and framework mechanism , Developers can design the corresponding GUI Graphical interface 、 Define the operation and response of different components 、 Capture the message of component or application and realize the linkage of interface display component and data storage component , So as to construct a complete application framework , Finally, we provide some of the realization of the old ape PyQt Development program interface to illustrate PyQt Interface styles of different components .

Through the introduction of the above , It helps to PyQt or Qt Beginners who don't know how to understand PyQt The basic development framework of 、 Application interface style .

Of course, it involves PyQt, also QML、PyQt5-sip And so on , These old apes have not been studied for the time being , Not much .

more PyQt The content of the development , Please refer to the old ape PyQT special column 《https://blog.csdn.net/laoyuanpython/category_9702362.html PyQt Introduction 》 Introduction to .

It's not easy to write , Please support :

If you can get something from reading this article , Please give me some compliments 、 Comment on 、 Collection , Thank you for your support !

Pay column on the old ape

  1. Paid column 《https://blog.csdn.net/laoyuanpython/category_9607725.html Use PyQt Developing graphical interfaces Python application 》 Special introduction based on Python Of PyQt Basic course of graphical interface development , The corresponding article directory is 《 https://blog.csdn.net//article/details/107580932 Use PyQt Developing graphical interfaces Python Application column Directory 》;
  2. Paid column 《https://blog.csdn.net/laoyuanpython/category_10232926.html moviepy Audio and video development column ) Detailed introduction moviepy The class correlation method of audio and video clip synthesis processing and the use of correlation method to process related clip synthesis scene , The corresponding article directory is 《https://blog.csdn.net//article/details/107574583 moviepy Audio and video development column Directory 》;
  3. Paid column 《https://blog.csdn.net/laoyuanpython/category_10581071.html OpenCV-Python Difficult problem set for beginners 》 by 《https://blog.csdn.net/laoyuanpython/category_9979286.html OpenCV-Python Graphics and image processing 》 The accompanying column of , It is the author's opinion of OpenCV-Python Some problems encountered in the study of graphics and image processing , The relevant data are basically the results of repeated studies of old apes , be conducive to OpenCV-Python Beginners have a deeper understanding of OpenCV, The corresponding article directory is 《https://blog.csdn.net//article/details/109713407 OpenCV-Python Catalog of difficult problem set for beginners 》
  4. Paid column 《https://blog.csdn.net/laoyuanpython/category_10762553.html Python Introduction to reptiles 》 From the perspective of Xiaobai, an Internet front-end developer, this paper introduces the knowledge and skills of crawler development , Including the basics of getting started with crawlers , And crawling CSDN The article information 、 Blogger information 、 Like the article 、 Comments, etc .

The first two columns are suitable for a certain amount of Python Xiaobai readers who are basic but have no relevant knowledge learn , In the third column, please combine 《https://blog.csdn.net/laoyuanpython/category_9979286.html OpenCV-Python Graphics and image processing 》 Learning to use .

For lack of Python Basic colleagues , Through the free column of the old ape 《https://blog.csdn.net/laoyuanpython/category_9831699.html special column :Python Basic course catalog ) Learn from scratch Python.

If you are interested and willing to support the old ape readers , Welcome to the paid column .

If you have questions about the content of the article , You can leave a message in the comments section of the blog , Or pay attention to : Old ape Python Wechat public number sends message for consultation .

Old ape Python, Learn from the old ape Python!

Go to the old ape Python Blog Directory https://blog.csdn.net/


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved