13.07.2015 Views

The wxPython tutorial

The wxPython tutorial

The wxPython tutorial

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Creating custom widgetshttp://www.zetcode.com/wxpython/customwidgets/Python IDEHome ContentsFaster, Easier Python Development Editor,Debugger, Browser, and moreFree Floor Plan SoftwareMake Floor Plans in Minutes See Examples.Free Download!Creating custom widgetsHave you ever looked at an application and wondered, how a particulargui item was created? Probably every wannabe programmer has. <strong>The</strong>nyou were looking at a list of widgets provided by your favourite guilibrary. But you couldn't find it. Toolkits usually provide only the mostcommon widgets like buttons, text widgets, sliders etc. No toolkit canprovide all possible widgets.<strong>The</strong>re are actually two kinds of toolkits. Spartan toolkits and heavyweight toolkits. <strong>The</strong> FLTK toolkit is a kind of a spartan toolkit. It providesonly the very basic widgets and assumes, that the programemer willcreate the more complicated ones himself. <strong>wxPython</strong> is a heavy weightone. It has lots of widgets. Yet it does not provide the more specializedwidgets. For example a speed meter widget, a widget that measures thecapacity of a CD to be burned (found e.g. in nero). Toolkits also don'thave usually charts.Programmers must create such widgets by themselves. <strong>The</strong>y do it byusing the drawing tools provided by the toolkit. <strong>The</strong>re are twopossibilities. A programmer can modify or enhance an existing widget. Orhe can create a custom widget from scratch.Here I assume, you have read the chapter on the GDI.A hyperlink widget<strong>The</strong> first example will create a hyperlink. <strong>The</strong> hyperlink widget will bebased on an existing wx.lib.stattext.GenStaticText widget.#!/usr/bin/python# link.pyimport wxfrom wx.lib.stattext import GenStaticTextimport webbrowserclass Link(GenStaticText):def __init__(self, parent, id=-1, label='', pos=(-1, -1),size=(-1, -1), style=0, name='Link', URL=''):GenStaticText.__init__(self, parent, id, label, pos, size, style, name)self.url = URL1 de 9 27/04/2008 1:07

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!