Wxpython 简明教程

wxPython - Major Classes

原始的 wxWidgets(用 C 语言编写)是一个庞大的类库。此库中的 GUI 类已通过 wxPython 模块移植到 Python,该模块尝试尽可能镜像原始 wxWidgets 库。因此,wxPython 中的 wx.Frame 类的作用与 C 版本中的 wxFrame 类非常相似。

Original wxWidgets (written in C) is a huge class library. GUI classes from this library are ported to Python with wxPython module, which tries to mirror the original wxWidgets library as close as possible. So, wx.Frame class in wxPython acts much in the same way as wxFrame class in its C version.

wxObject 是大多数类的基础。wxApp(wxPython 中的 wx.App)的对象表示应用程序本身。在生成 GUI 后,应用程序通过 MainLoop() 方法进入事件循环。以下图表描绘了 wxPython 中包含的最常用 GUI 类的类层次结构。

wxObject is the base for most of the classes. An object of wxApp (wx.App in wxPython) represents the application itself. After generating the GUI, application enters in an event loop by MainLoop() method. Following diagrams depict the class hierarchy of most commonly used GUI classes included in wxPython.

wxwindow class hierarchy
wxgdiobject class hierarchy
wxsizer class hierarchy
wxbutton class hierarchy

S.N.

Classes & Description

1

wx.Framewx.Frame Class has a default constructor with no arguments.

2

wx.Panelwx.Panel class is usually put inside a wxFrame object. This class is also inherited from wxWindow class.

3

wx.StaticTextwx.StaticText class object presents a control holding such read-only text. It can be termed as a passive control since it doesn’t produce any event.

4

TextCtrlIn wxPython, an object of wx.TextCtrl class serves this purpose. It is a control in which the text can be displayed and edited.

5

RadioButton & RadioBoxEach button, an object of wx.RadioButton class carries a text label next to a round button. wxPython API also consists of wx.RadioBox class. Its object offers a border and label to the group.

6

wx.CheckBoxA checkbox displays a small labeled rectangular box. When clicked, a checkmark appears inside the rectangle to indicate that a choice is made.

7

ComboBox & Choice ClassA wx.ComboBox object presents a list of items to select from. It can be configured to be a dropdown list or with permanent display. wxPython API contains a wx.Choice class, whose object is also a dropdown list, which is permanently read-only.

8

Wx.GaugeWx.Gauge class object shows a vertical or horizontal bar, which graphically shows incrementing quantity.

9

wx.SliderwxPython API contains wx.Slider class. It offers same functionality as that of Scrollbar. Slider offers a convenient way to handle dragging the handle by slider specific wx.EVT_SLIDER event binder.

10

wx.MenuBarA horizontal bar just below the title bar of a top level window is reserved to display a series of menus. It is an object of wx.MenuBar class in wxPython API.

11

wx.ToolbarIf the style parameter of wx.Toolbar object is set to wx.TB_DOCKABLE, it becomes dockable. A floating toolbar can also be constructed using wxPython’s AUIToolBar class.

12

Wx.DialogAlthough a Dialog class object appears like a Frame, it is normally used as a pop-up window on top of a parent frame. The objective of a Dialog is to collect some data from the user and send it to the parent frame.

13

wx.Notebookwx.Notebook widget presents a tabbed control. One Notebook object in a frame has one or more tabs (called Pages), each of them having a panel showing the layout of controls.

14

wx.SplitterWindowObject of this class is a layout manager, which holds two subwindows whose size can be changed dynamically by dragging the boundaries between them. The Splitter control gives a handle that can be dragged to resize the controls.

15

HTMLWindowwxHTML library contains classes for parsing and displaying HTML content. Although this is not intended to be a full-featured browser, wx.HtmlWindow object is a generic HTML viewer.

16

ListBox & ListCtrlA wx.ListBox widget presents a vertically scrollable list of strings. By default, a single item in the list is selectable. ListCtrl widget is a highly enhanced list display and selection tool. List of more than one column can be displayed in Report view, List view or Icon view.