Size: 3175
Comment: missing edit-log entry for this revision
|
Size: 7306
Comment: link to transana and task coach
|
Deletions are marked like this. | Additions are marked like this. |
Line 1: | Line 1: |
How to learn wxPython. | = How to learn wxPython. = [[TableOfContents]] |
Line 3: | 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 6: | 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 15: | Line 8: |
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. |
Without first understanding topics such as functions, modules, and classes, adding wxPython to the mix will only increase the confusion. |
Line 19: | Line 10: |
To learn Python, go to the Python for Beginners page at the main Python web site: |
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 22: | Line 12: |
http://www.python.org/doc/Newbies.html | == 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/ |
Line 24: | Line 15: |
Follow the links on that page, and you should find something to your liking. |
== 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. |
Line 27: | Line 18: |
Once you have a fundamental understanding of programming in Python, you can start to learn wxPython for GUI programming. |
Another couple of good places to look in the Wiki are the ObstacleCourse and the FullyFunctionalDemo. |
Line 30: | Line 20: |
I would suggest starting with the Tutorial. It is brief, and not complete, but it is a good start. You can find it here: |
There is also a very old, brief Tutorial available. You can find it here: |
Line 35: | Line 24: |
Once you have gone through that, you might want to go through the wxpython wiki getting started section: |
It can be helpful, but it is written using an outdated coding style, so read the ["wxPython Style Guide"] before viewing it. |
Line 38: | Line 26: |
http://wiki.wxpython.org/index.cgi/Getting_20Started | {{{wx.Frame}}}, rather than the old wxFrame. |
Line 40: | Line 28: |
Between these two, you should have a basic grasp of how wxPython works, and be ready to make you own application. To so 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 44: | Line 30: |
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. |
== Choose a Good Editor == Features such as auto-completion, code highlighting, and an interactive window make for faster programming with less errors. |
Line 51: | Line 33: |
Another source of examples is the wxPython cookbook: | See http://wiki.python.org/moin/PythonEditors for a list of editors. |
Line 53: | Line 35: |
http://wiki.wxpython.org/index.cgi/wxPython_20Cookbook | == 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. |
Line 55: | 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 | |
Line 56: | Line 40: |
The reference manual for wxPython is the same as the reference for the C++ version of wxWindows, and can be found here: |
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" [http://www.transana.org/ Transana] and [http://www.taskcoach.org/ 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: |
Line 61: | Line 57: |
It is written in C++ syntax, with notes inserted for 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 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. |
As of this writing, that version is a bit out of date, so you can try the wxWidgets site instead: |
Line 71: | Line 59: |
[NOTE: it would be great if someone would add a section here with examples of how to translate from C++ to Python.] |
http://www.wxwidgets.org/manuals/2.8.4/wx_contents.html |
Line 74: | 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. | |
Line 75: | Line 63: |
There is also a new, automatically generated reference in Python syntax. You can find it here: | |
Line 76: | Line 65: |
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 use of gmane. This and many other mailing lists are converted into the NNTP Protocol. This newsgroup is then called "gmane.comp.python.wxpython". Using a newsreader is IMHO much more convenient than an email client. (Franz Steinhäusler). |
How to learn wxPython.
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" [http://www.transana.org/ Transana] and [http://www.taskcoach.org/ 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 use of gmane. This and many other mailing lists are converted into the NNTP Protocol. This newsgroup is then called "gmane.comp.python.wxpython". Using a newsreader is IMHO much more convenient than an email client. (Franz Steinhäusler).