[Tutor] Creating custom GUI elements
Alan Gauld
alan.gauld at btinternet.com
Sat Sep 4 22:23:27 CEST 2010
"aug dawg" <augdawg09 at gmail.com> wrote
> How would I go about creating custom GUI elements? For example, if I
> wanted
> to make a simple LEGO maker app, how would I write the code for the
> bricks
> so that the user could drag them around and then build LEGO models?
You find the nearest widget to what you want then you create a new
subclass
of that widget. Then you override all the methods that act
differently. Then you
add any new methods that are unique to your widget.
If there is nothing really like it you may need to go up to the
abstract
widgets like Window and use composition to build a new widget built
from the standard ones. Thats even harder because thre is less you
get to reuse for free.
If its a 3D widget you may want to start with Pygame rather than a
standard GUI tooklit...
Warning, it's a non trivial exercise thats a pain to get exactly right
unless its
a very minor tweak to an existing widget. But there is no real
alternative.
The good news is that once you get it right the final app that uses it
will be
a snap by comparison!
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list