Differences between revisions 42 and 43
Revision 42 as of 2007-09-04 21:39:03
Size: 7040
Editor: 68-89-149-2
Comment:
Revision 43 as of 2007-09-09 11:16:22
Size: 7183
Editor: M3150P009
Comment:
Deletions are marked like this. Additions are marked like this.
Line 2: Line 2:
Line 5: Line 4:
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.
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.
Line 8: Line 6:
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.
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.
Line 17: Line 8:
Without first understanding topics such as functions, modules, and
classes, adding wxPython to the mix will only increase the confusion.
Without first understanding topics such as functions, modules, and classes, adding wxPython to the mix will only increase the confusion.
Line 20: Line 10:
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.
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.
Line 26: Line 13:
Line 30: Line 16:
Once you have a fundamental understanding of programming in Python, you
can start to learn wxPython for GUI programming. I suggest starting with the wxPython wiki ["Getting Started"] section.
Once you have a fundamental understanding of programming in Python, you can start to learn wxPython for GUI programming. I suggest starting with the wxPython wiki ["Getting Started"] section.
Line 41: Line 26:
`wx.Frame`, rather than the old wxFrame. {{{wx.Frame}}}, rather than the old wxFrame.
Line 43: Line 28:
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.
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.
Line 48: Line 31:
Features such as auto-completion, code highlighting, and an interactive window
make for faster programming with less errors.
Features such as auto-completion, code highlighting, and an interactive window make for faster programming with less errors.
Line 54: Line 36:
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.
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.
Line 61: Line 38:
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
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 69: Line 43:
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.
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.
Line 75: Line 46:
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.
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.
Line 80: Line 48:
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. There is a huge difference between the small examples on this wiki, and actual real-world code, so the process of analyzing large applications is integral to learning wxPython.
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. There is a huge difference between the small examples on this wiki, and actual real-world code, so the process of analyzing large applications is integral to learning wxPython.
Line 86: Line 50:
[http://ShowMeDo.com ShowMeDo.com] hosts a set of [http://showmedo.com/videos/series?name=PythonWxPythonBeginnersSeries five tutorial videos]
which will be useful to those just starting with wxPython.
[http://ShowMeDo.com ShowMeDo.com] hosts a set of [http://showmedo.com/videos/series?name=PythonWxPythonBeginnersSeries five tutorial videos] which will be useful to those just starting with wxPython.
Line 90: Line 53:
The reference manual for wxPython is the same as the reference for the
C++ version of wxWidgets, and can be found here:
The reference manual for wxPython is the same as the reference for the C++ version of wxWidgets, and can be found here:
Line 93: Line 55:
[http://www.wxpython.org/onlinedocs.php] http://www.wxpython.org/onlinedocs.php
Line 97: Line 59:
[http://www.wxwidgets.org/manuals/2.8.4/wx_contents.html] http://www.wxwidgets.org/manuals/2.8.4/wx_contents.html
Line 99: Line 61:
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.
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.
Line 112: Line 65:
[http://www.wxpython.org/docs/api/] http://www.wxpython.org/docs/api/
Line 114: Line 67:
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.
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.
Line 119: Line 70:
Line 125: Line 75:

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.
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 132: Line 78:
Another possibiltiy is to make news of gname. This and many other mailing lists are mirrored into the NNTP Protocol. Using a newsreader is much more convenient as an email client. (Franz Steinhäusler).

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

The Python website has an excellent guide for beginners that takes you step-by-step through the process of learning the language. http://www.python.org/about/gettingstarted/

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 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. You can find it here:

http://wxpython.org/tutorial.php

It can be helpful, but it is written using an outdated coding style, so read the ["wxPython Style Guide"] before viewing it.

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 for a list of editors.

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. There is a huge difference between the small examples on this wiki, and actual real-world code, so the process of analyzing large applications is integral to learning wxPython.

[http://ShowMeDo.com ShowMeDo.com] hosts a set of [http://showmedo.com/videos/series?name=PythonWxPythonBeginnersSeries five tutorial videos] which will be useful to those just starting with wxPython.

The API

The reference manual for wxPython is the same as the reference for the C++ version of wxWidgets, 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.8.4/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.

Coding Style

It will serve you well to use a nice, modern style for your wxPython code. Due to API changes over the years, and just plain experience, wxPython code style has changed quite a bit over the years, and gotten much more Pythonic.

Unfortunately, a lot of the examples you'll find have not been updated to reflect this style. As you will benefit from using good, modern, style, make sure to study ["wxPython Style Guide"] right when you get started, to establish good habits.

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.

Comments

Another possibiltiy is to make news of gname. This and many other mailing lists are mirrored into the NNTP Protocol. Using a newsreader is much more convenient as an email client. (Franz Steinhäusler).

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.