Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to analyze Python GUI Interface programming

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

Today, I will talk to you about how to analyze Python GUI interface programming, many people may not know much about it. In order to make you understand better, the editor has summarized the following for you. I hope you can get something according to this article.

Graphical user interface (Graphical User Interface, referred to as GUI, also known as graphical user interface) refers to the graphical display of the computer operation user interface. Compared with the command line interface used by early computers, the graphical interface is more visually acceptable to users. However, if this interface is to prompt the user for "state change" with "all kinds of beautiful but not monotonous visual messages" at a specific position on the display screen, it is bound to take more computing power than simple message presentation. In GUI, instead of just typing and returning text, users can see graphics such as windows, buttons, text boxes, and so on, and they can click with the mouse or type through the keyboard. GUI is a different way to interact with the program. Overview of GUI

Common framework of Python GUI

Flexx

Flexx is a pure Python toolkit for creating a graphical user interface (GUI) that uses Web technology for rendering. The application is written entirely in Python; the PScript converter dynamically generates the necessary JavaScript.

Project address: https://github.com/flexxui/flexx

Getting started Guide: https://flexx.readthedocs.io/en/stable/guide/index.html

Installation

Flexx requires Python 3.5 cycles, which is also applicable to pypy. In addition, it relies on the following libraries

Tornado library (pure Python).

PScript Library (pure Python flexxui project)

Webruntime Library (pure Python flexxui project)

Dialite Library (pure Python flexxui project)

To install the latest version (and dependencies), use any of the following commands:

Pip install flexx

Conda install flexx-c conda-forge

Or use the following ways to get updates:

Pip install https://github.com/flexxui/flexx/archive/master.zip

WxPython

WxPython is a cross-platform GUI toolkit for the Python programming language. It allows Python programmers to easily and easily create programs with robust and powerful graphical user interfaces. It is implemented as a set of Python extension modules that wrap the GUI components of a popular wxWidgets cross-platform library written in C + +.

Official website: https://www.wxpython.org/

Kivy

Kivy is an open source Python library for developing mobile applications and other multi-touch applications with natural user interfaces. It can be executed on Android,iOS, Linux,OS X and Windows. Under the MIT license terms, Kivy is free and open source software.

Official website: https://kivy.org/

PyQt

PyQt is a set of Python v2 and v3 bindings of Qt's Qt application framework that can run on all platforms supported by Qt, including Windows,OS XMagi Linux Magi iOS and Android. PyQt5 supports Qt v5. PyQt4 supports Qt v4 and will be built against Qt v5. Binding is implemented as a set of Python modules containing more than 1000 classes.

Official website: https://www.riverbankcomputing.com/software/pyqt/intro

Tkinter

Tkinter is a module that uses python to design windows. The Tkinter module ("Tk interface") is the interface of Python's standard Tk GUI toolkit. As a python-specific GUI interface, is an image window, tkinter is python's own, can be edited GUI interface, we can use GUI to achieve a lot of intuitive functions, such as want to develop a calculator, if it is only a program input, output window, it is useless user experience. It is necessary to develop a small graphic window.

Index: https://wiki.python.org/moin/TkInter

Pywin32

Windows Pywin32 allows you to use PYTHON to develop win32 applications in the same way as VC. The code style can be similar to win32 sdk or MFC, as you choose. If you still don't give up the same code process as vc under python, then this is a good choice.

Project address: https://github.com/mhammond/pywin32

PyGTK

PyGTK allows you to easily create programs with a graphical user interface with Python

Official website: https://pygobject.readthedocs.io/en/latest/

Create an application

Use the wxPython framework

Installation

For Windwos and MAC platforms, it takes only one command to install wxPython using the pip tool:

Pip install-U wxPython

Linux platform:

Because there are multiple options for distributions and wx ports (GTK2 or GTK3), files cannot all be in the same folder for easy access through pip. This just means that you need to refine further to find the URL to be provided to pip. For example, to get a GTK3 wxPython build for Ubuntu 16.04 (and 16.10 https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-16.04 Mint 18 and other versions), you can use the following pip command: pip install-U\-f Linux\ wxPython

Prepare for

Note: knowledge sources and networks in this part

Before using wxPython, learn about two basic objects: the application object and the top-level window.

The application object manages the main event loop, which is the power of the wxPython program. Without an application object, the wxPython application will not run.

Top-level windows are often used to manage the most important data, control it, and present it to users.

The relationship between the two basic objects and the rest of the application is shown in the following figure:

This application object has a top-level window and a main loop event. The top-level window manages the components in its window and other data objects assigned to it. The events triggered by the window and its components are based on the user's actions and accept event notifications to change the display.

Hell Word

Code:

Import wx

App = wx.App (False)

Frame = wx.Frame (None,wx.ID_ANY, "that's how you should learn from Linux")

Frame.Show (show=True)

App.MainLoop () parsing:

Note:

You can replace wx.ID_ANY,-1 with-1, which means the default value. In addition, wxWidgets also provides other standard ID (v2.8). You can also customize an ID, but Getting Started with wxPython believes that there is no reason to do that, and it is better to use a standard ID.

The complete syntax of wx.Frame is:

Wx.Frame (parent, id=-1, title= "", pos=wx.DefaultPosition,size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE,name= "frame")

Parent: the parent window of the frame. If it is a top-level window, this value is None.

Id: the wxPython ID number for the new window. It is usually set to-1 to let wxPython automatically generate a new ID.

Title: the title of the window.

Pos: a wx.Point object that specifies the position of the upper-left corner of the new window on the screen. In a graphical user interface program, it is usually the upper-left corner of the display (0minute 0). This default value (- 1) will allow the system to determine the location of the window.

Size: a wx.Size object that specifies the initial size of the window. This default value (- 1) will allow the system to determine the initial size of the window.

Style: a constant that specifies the type of window. You can use or operate to combine them.

Name: the name inside the framework. You can use it to find this window.

After reading the above, do you have any further understanding of how to analyze Python GUI interface programming? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report