返回介绍

Introduction to wxPython

发布于 2025-02-22 22:19:36 字数 8839 浏览 0 评论 0 收藏 0

An application is a computer program that performs a specific task or a group of tasks. Web browser, media player, word processor are examples of typical applications. A term tool or utility is used for a rather small and simple application that performs a single task. A UNIX cp program is an example of a such a tool. All these together form computer software. Computer software is the broadest term used to describe the operating system, data, computer programs, applications, mp3 files or computer games. Applications can be created for four different areas.

Application areas
Figure: Application areas

Online shopping applications, wikis, weblogs are examples of popular web applications. They are accessed with a web browser. Examples of desktop applications include Maya, Opera, Open Office or Winamp. Enterprise computing is a specific area. Applications in these area are complex and large. Applications created for portables include all programs developed for mobile phones, communicators, PDAs and similar.

Programming languages

There are currently several widely used programming languages. The following list is based on the TIOBE Programming Community Index. The numbers are from October 2014.

PositionLanguageRatings
1C17.6%
2Java13.5%
3Objective-C10.1%
4C++4.8%
5C#4.7%
6Basic3.5%
7PHP2.9%
8Python2.3%
9Perl2.1%
10Transact-SQL2.1%

Python belongs to the ten most popular computer languages.

Python

Python logo Python is a successful scripting language. It was initially developed by Guido van Rossum. It was first released in 1991. Python was inspired by ABC and Haskell programming languages. Python is a high level, general purpose, multiplatform, interpreted language. Some prefer to call it a dynamic language. It is easy to learn. Python is a minimalistic language. One of its most visible features is that it does not use semicolons nor brackets. Python uses indentation instead. Today Python is maintained by a large group of volunteers worldwide.

For creating graphical user interfaces, python programmers can choose among three decent options: PyGTK, wxPython, and PyQt.

wxPython

wxPython is a cross platform toolkit for creating desktop GUI applications. The principal author of wxPython is Robin Dunn. With wxPython developers can create applications on Windows, Mac and on various Unix systems. wxPython is a wrapper around wxWidgets, which is a mature cross platform C++ library. wxPython consists of the five basic modules.

wxPython modules
Figure: wxPython modules

Controls module provides the common widgets found in graphical applications. For example a Button, a Toolbar, or a Notebook. Widgets are called controls under Windows OS. The Core module consists of elementary classes that are used in development. These classes include the Object class, which is the mother of all classes, Sizers, which are used for widget layout, Events, basic geometry classes like Point and Rectangle. The Graphics Device Interface (GDI) is a set of classes used for drawing onto the widgets. This module contains classes for manipulation of Fonts, Colours, Brushes, Pens or Images. The Misc module contains of various other classes and module functions. These classes are used for logging, application configuration, system settings, working with display or joystick. The Windows module consists of various windows that form an application, for instance a Panel, a Dialog, a Frame, or a Scrolled Window.

wxPython API

wxPython API is a set of methods and objects. Widgets are essential building blocks of a GUI application. Under Windows widgets are calles controls. We can roughly divide programmers into two groups. They code applications or libraries. In our case, wxPython is a library that is used by application programmers to code applications. Technically, wxPython is a wrapper over a C++ GUI API called wxWidgets. So it is not a native API. e.g. not written directly in Python.

In wxPython we have lots of widgets. These can be divided into some logical groups.

Base Widgets

These widgets provide basic functionality for derived widgets. They are called ancestors. They are usually not used directly.

Base widgets
Figure: Base widgets

Top level Widgets

These widgets exist independently of each other.

Top-level widgets
Figure: Top-level widgets

Containers

Containers contain other widgets.

Containters
Figure: Containers

Dynamic Widgets

These widgets can be edited by users.

Dynamic widgets
Figure: Dynamic widgets

Static Widgets

These widgets display information. They cannot be edited by user.

Static widgets
Figure: Static widgets

Other Widgets

These widgets implement statusbar, toolbar and menubar in an application.

Other widgets
Figure: Other widgets

Inheritance

There is a specific relation among widgets in wxPython. This relation is developed by inheritance. The inheritance is a crucial part of the object oriented programming. Widgets form a hierarchy. Widgets can inherit functionality from other widgets. Existing classes are called base classes, parents, or ancestors. The widgets that inherit we call derived widgets, child widgets or descendants. The terminology is borrowed from biology.

Inheritance diagram
Figure: Inheritance diagram

Say we use a button widget in our application. The button widget inherits from 4 different base classes. The closest class is the wx.Control class. A button widget is a kind of a small window. All widgets that appear on the screen are windows. Therefore they inherit from wx.Window class. There are objects that are invisible. Examples are sizers, device context or locale object. There are also classes that are visible but they are not windows. For example a colour object, caret object or a cursor object. Not all widgets are controls. For example wx.Dialog is not a kind of control. The controls are widgets that are placed on other widgets called containers. That's why we have a separate wx.Control base class.

Every window can react to events. So does the button widget. By clicking on the button, we launch the wx.EVT_COMMAND_BUTTON_CLICKED event. The button widget inherits the wx.EvtHandler via the wx.Window class. Each widget that reacts to events must inherit from wx.EvtHandler class. Finally all objects inherit from wx.Object class. This is the Eve, mother of all objects in wxPython.

This was an introduction to wxPython.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文