Differences between revisions 1 and 32 (spanning 31 versions)
Revision 1 as of 2001-11-01 18:42:18
Size: 3175
Editor: anonymous
Comment: missing edit-log entry for this revision
Revision 32 as of 2006-01-04 05:07:07
Size: 6612
Editor: ool-44c14de8
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
How to learn wxPython. = How to learn wxPython. =

[[TableOfContents]]
Line 4: Line 6:
learning wxPython. this page gives some pointers on how to do just that. learning wxPython.  This page gives some pointers on how to do just that.
Line 15: Line 17:
Without first understanding topics such as functions, modules, and
classes, adding wxPython to the mix will only increase the confusion.
Line 19: Line 24:
To learn Python, go to the Python for Beginners page at the main Python
web site:

== Learn Python ==
If you don't know programming then this link is your best bet:
Line 24: Line 30:
Follow the links on that page, and you should find something to your
liking.
If you are already familiar with programming but still need to
learn Python, then the Python Tutorial is a good place to start:
Line 27: Line 33:
http://www.python.org/doc/current/tut/tut.html

== Learn wxPython ==
Line 28: Line 37:
can start to learn wxPython for GUI programming. can start to learn wxPython for GUI programming. I suggest starting with
the The wxPython wiki ["Getting Started"] section
Line 30: Line 40:
I would suggest starting with the Tutorial. It is brief, and not
complete, but it is a good start. You can find it here:
Another couple of good places to look in the Wiki are:

the ObstacleCourse

and

the FullyFunctionalDemo.

There is also a very old, brief Tutorial available. It can be helpful,
but it is written using an outdated coding style.

You can find it here:
Line 35: Line 55:
Once you have gone through that, you might want to go through the
wxpython wiki getting started section:
Note that the big style difference is that it uses a now-depricated way of importing the wxPython modules:
Line 38: Line 57:
http://wiki.wxpython.org/index.cgi/Getting_20Started `from wxPython import *`

You shouldn't use this anymore. Instead, use:

`import wx`

After that, all the wxPython stuff will be in the `wx` namespace and can be refered to like this:

`wx.Frame`, rather than the old wxFrame.
Line 41: Line 68:
and be ready to make you own application. To so this, you will want two and be ready to make your own application. To do this, you will want two
Line 44: Line 71:
== Choose a Good Editor ==
Features such as auto-completion, code highlighting, and an interactive window
make for faster programming with less errors.
See http://wiki.python.org/moin/PythonEditors.

== The Comprehensive Demo Files ==
Line 51: Line 84:
Another source of examples is the wxPython cookbook: If you can't find it in your installation:
Here are the most recent versions are downloadable from Source''''''Forge. Just
get the wxPython''''''Demo archive from that has the same version number as your
wxPython installation from here: https://sourceforge.net/project/showfiles.php?group_id=10718
Line 53: Line 89:
http://wiki.wxpython.org/index.cgi/wxPython_20Cookbook Another source of examples is the ["wxPython Cookbook"].

== Play with the Demo Code ==
Once you find a control you are interested in using, copy the demo code to your editor
and delete all the unnecessary code until you find the statements that "do the work."
Then experiment with changing the arguments passed to the control’s constructor until
you understand how it works. Only then add the control to a larger application you are developing.

== Study Other People's Code ==
Charles Simonyi, the legendary Microsoft programmer, grew up in Hungary and had
few books available to him from which to learn computer science. He was able
to get the source code for a compiler and studied the printouts as musicians
would study musical scores.

There are quite a few gems in the sample code that is distributed with wxPython but
are not in the Demo program, e.g., FrogEdit and its underlying wx.lib.editor module.
I had assumed that an editor would be a wx.TextCtrl on steroids. I was surprised to
see that the text was drawn to the screen using a DC (device control) and learned
some good techniques. I am also "reading" Transana and Task Coach, two sophisticated
applications written in Python and wxPython, to learn how large applications are structured.
Line 56: Line 111:

== The API ==
Line 59: Line 116:
http://www.wxpython.org/onlinedocs.php [http://www.wxpython.org/onlinedocs.php]
Line 61: Line 118:
It is written in C++ syntax, with notes inserted for when the Python As of this writing, that version is a bit out of date, so you can try the wxWidgets site instead:

[http://www.wxwidgets.org/manuals/2.6.2/wx_contents.html]

It is written in C++ syntax, with notes inserted when the Python
Line 67: Line 128:
to learn to translate form the C++ in the docs to the equivalent
Python. One of the best way to learn to do this is to compare code form
the examples n the wxPython demo to what is in the reference manual.
to learn to translate from the C++ in the docs to the equivalent
Python. One of the best ways to learn to do this is to compare code from
the examples in the wxPython demo to what is in the reference manual.  There
is also the ["C++GuideForwxPythoneers"] page on this site to help you further.
Line 71: Line 133:
[NOTE: it would be great if someone would add a section here with
examples of how to translate from C++ to Python.]
There is also a new, automatically generated reference in Python syntax. You can find it here:

[http://www.wxpython.org/docs/api/]

I keep the wxWidgets documentation open in one window and the wxPython Demo
in another as I use PythonWin to develop my programs. I often refer to
these resources often and copy code into my application.

== Live Help ==

The wxPython-users mailing list is famous for its helpful and friendly members. You can subscribe to it here: http://wxpython.org/maillist.php.
I often find techniques that I may need for the future and save them to a special folder.
After I developed some ability in wxPython, I try to solve some of the questions posed
to the community before I read the answer posted by a more experienced programmer.
Line 75: Line 149:
And now a channel on irc.freenode.net has been started #python.
Line 76: Line 151:
= Comments =

How to learn wxPython.

TableOfContents

We have had a lot of questions on the newsgroup asking how to go about learning wxPython. This page gives some pointers on how to do just that.

First of all, if you are new to Python, and especially if you are new to programming in general, it makes the most sense to learn Python itself first, without any GUI stuff. This can be frustrating if your goal is to write GUI programs, and particularly if you have experience with an environment like Visual Basic in which GUI programming is integrated into the environment. It is worth it, however, to take some time to learn about Python. Python is a very powerful language capable of doing many things both with and without GUIs.

Without first understanding topics such as functions, modules, and classes, adding wxPython to the mix will only increase the confusion.

Using wxPython requires a pretty good understanding of Object Oriented (OO) programming in Python, and all of the tutorials and references that I will refer to later assume this knowledge.

Learn Python

If you don't know programming then this link is your best bet:

http://www.python.org/doc/Newbies.html

If you are already familiar with programming but still need to learn Python, then the Python Tutorial is a good place to start:

http://www.python.org/doc/current/tut/tut.html

Learn wxPython

Once you have a fundamental understanding of programming in Python, you can start to learn wxPython for GUI programming. I suggest starting with the The wxPython wiki ["Getting Started"] section

Another couple of good places to look in the Wiki are:

the ObstacleCourse

and

the FullyFunctionalDemo.

There is also a very old, brief Tutorial available. It can be helpful, but it is written using an outdated coding style.

You can find it here:

http://wxpython.org/tutorial.php

Note that the big style difference is that it uses a now-depricated way of importing the wxPython modules:

from wxPython import *

You shouldn't use this anymore. Instead, use:

import wx

After that, all the wxPython stuff will be in the wx namespace and can be refered to like this:

wx.Frame, rather than the old wxFrame.

Between these two, you should have a basic grasp of how wxPython works, and be ready to make your own application. To do this, you will want two things: examples and a reference.

Choose a Good Editor

Features such as auto-completion, code highlighting, and an interactive window make for faster programming with less errors. See http://wiki.python.org/moin/PythonEditors.

The Comprehensive Demo Files

The wxPython demo is your best source of examples. It is distributed with wxPython, and demonstrates virtually all the features of wxPython. When you run it, you can see how different features work, and see the source code that made it happen. Many of us look for something in the demo that is close to what we want to do, copy it, and then alter it to fit our needs.

If you can't find it in your installation: Here are the most recent versions are downloadable from SourceForge. Just get the wxPythonDemo archive from that has the same version number as your wxPython installation from here: https://sourceforge.net/project/showfiles.php?group_id=10718

Another source of examples is the ["wxPython Cookbook"].

Play with the Demo Code

Once you find a control you are interested in using, copy the demo code to your editor and delete all the unnecessary code until you find the statements that "do the work." Then experiment with changing the arguments passed to the control’s constructor until you understand how it works. Only then add the control to a larger application you are developing.

Study Other People's Code

Charles Simonyi, the legendary Microsoft programmer, grew up in Hungary and had few books available to him from which to learn computer science. He was able to get the source code for a compiler and studied the printouts as musicians would study musical scores.

There are quite a few gems in the sample code that is distributed with wxPython but are not in the Demo program, e.g., FrogEdit and its underlying wx.lib.editor module. I had assumed that an editor would be a wx.TextCtrl on steroids. I was surprised to see that the text was drawn to the screen using a DC (device control) and learned some good techniques. I am also "reading" Transana and Task Coach, two sophisticated applications written in Python and wxPython, to learn how large applications are structured.

The API

The reference manual for wxPython is the same as the reference for the C++ version of wxWindows, and can be found here:

[http://www.wxpython.org/onlinedocs.php]

As of this writing, that version is a bit out of date, so you can try the wxWidgets site instead:

[http://www.wxwidgets.org/manuals/2.6.2/wx_contents.html]

It is written in C++ syntax, with notes inserted when the Python implementation differs from the C++. The fact that the docs are written for C++ is unfortunate, not because they aren't useful to Python programmers, but because is can be very intimidating to new users who don't know C++. In fact, many Python programmers who don't know a bit of C++ find that the docs can be very useful. It only takes a little while to learn to translate from the C++ in the docs to the equivalent Python. One of the best ways to learn to do this is to compare code from the examples in the wxPython demo to what is in the reference manual. There is also the ["C++GuideForwxPythoneers"] page on this site to help you further.

There is also a new, automatically generated reference in Python syntax. You can find it here:

[http://www.wxpython.org/docs/api/]

I keep the wxWidgets documentation open in one window and the wxPython Demo in another as I use PythonWin to develop my programs. I often refer to these resources often and copy code into my application.

Live Help

The wxPython-users mailing list is famous for its helpful and friendly members. You can subscribe to it here: http://wxpython.org/maillist.php. I often find techniques that I may need for the future and save them to a special folder. After I developed some ability in wxPython, I try to solve some of the questions posed to the community before I read the answer posted by a more experienced programmer.

And now a channel on irc.freenode.net has been started #python.

Comments

wxPython by Example (last edited 2012-06-28 08:10:48 by SWM-HIGH-SPEED2-22)

NOTE: To edit pages in this wiki you must be a member of the TrustedEditorsGroup.