- #pragma section-numbers off
Tutorials Challenge (Newbie)
Abstract: Read tutorials and try things out.
Motivation: Tutorials show you how to do something, then Challenges stretch you further.
Getting Started - the best tutorial today. (2003-09-17)
wxWidgets documentation. It's in C++, but that's okay.
There is a ''really old'' tutorial you could look at too, if you really wanted to.
This challenge has N parts:
Part 1: A First Application
Create the app in Section 5 of Getting Started.
Change the example to show two frames, instead of one.
If it hangs, kill python, and consider your code...
After it all works, you may want to poke around documentation. What's App do? wxapp Glance at the wxApp documentation to see what it does.
The wxWidgets documentation is a resource to become familiar with. Yes, it's in C++, but it is still very useful. If you've installed on Windows, you may have Start|Programs|wxPython|wxWidgets Reference. This is the same information, but compact and quick.
Under Gentoo Linux you can emerge dev-python/wxpython-docs separately and you get a python app called viewdocs.py and two zip Files in /usr/doc/wxPython-184.108.40.206/docs/. The python app is a help system with the wxWidgets and OGL Reference. There should be packages for other distros, too (most likely called wxpython-docs), but I don't know for sure.
Part 2: Little Editor
Now do Section 6 of Getting Started. Construct the little editor described.
When you get to section 6.2.4 ("More magic"), do what's necessary to hook up the OnOpen method. Run it. Make sure it works.
Now, we have a few changes to make:
Make two menu bar items: File and Help.
Under File, have: Open, Save, Save As, a separator, and then Exit.
Under Help, have: About.
Change OnOpen to set the title of the app's frame to be the filename.
Write OnSave; You can do it in 1-3 lines of code.
Write OnSaveAs; Only a little longer.
Part 3: and then you must BLAH.
I'm not done writing this challenge yet. Regardless: Keep going through the tutorial, trying things out. -- LionKimbro 2003-08-26 11:34:58
Questions for people who attempted the challenge:
- How long did it take to finish?
- What unreasonable problems did you confront in the challenge?
- How can this be improved?
- Anything else?
-- LionKimbro 2003-08-10 14:11:30
Cake. It took a couple sittings to finish part 2; no more than an hour in total. Part one was trivially easy. Although, obnoxiously, every time I run wxPython code XP claims that there's an error and (falsely) that python will shut down. I misspelled control.GetValue() when I was writing OnSave, and vaporized the contents of one of my text files. Be careful, kids!
I don't know about your XP error; I've used Python on WinXP, but don't remember something like that. Glad to hear you finished so quickly! -- LionKimbro 2003-09-03 10:04:33
I also took about 1 hour to finish part 2. I will suggest another change in the small editor: Implement a method OnSaveAs & OnSave. -- drudi
I'm happy to hear it! OnSave was already part of the challenge, but OnSaveAs wasn't- I've added it. Thank you for the feedback!
-- LionKimbro 2003-09-17
Good tutorial so far. It took me about 20 minutes total. I'm familliar with Tkinter, but am just getting started with wxPython. A comprehensive tutorial like what is available for Tkinter would be really helpful, so I may try to add some more stuff here...
-- jweage 2004-01-02
I'm not involved in the writing of the tutorial- just the ObstacleCourse. But I'm happy to hear you'll work on the tutorial..!
Can you tell me which tutorial you found for Tkinter that you really liked? I'm just curious. I like to look at tutorials- especially good ones..!
-- LionKimbro 2004-01-10 19:09:31
I stumbled through this one without too much trouble. About 2 hours filesystem time between helloworld.py and part2status.py, but I was multitasking. After I got Open, Save, and Save As working, I twiddled the idle statusbar so it reflected those actions (Saved filename OK and the like). For Part 3, if you want to stick with the editor code, you could try the ToolBar (I poked at it) or try and get Styled Text working (C++ API docs said Windows Only too often, didn't try it). MDI would probably be too much for this level (newbie). General gripes about the tutorial and wxPy I'll save for my wiki page.
-- AdricNet 2021-09-21 23:36:41
I thought this was an excellent challenge. I'm a newbie Python programmer, and I started on Tkinter, but I only used it for a few days -- I despised the way that dirty tricks constantly had to be used to get GUIs to display properly. Where Tkinter clicked in right away, I had a bit of trouble with wxPython at first -- but, I'm getting a little better every day, and I've found that in the long run, it's easier to get wxPython to do what you want it to do. A few things:
I know it's not a wxPython tutorial, but an astonishingly excellent tutorial that helped me learn and understand Tkinter, was called Thinking in Tkinter, and it's available at www.ferg.org/thinking_in_tkinter/.
- For part 2? Hmm, well, I had lots of fun poking around... here are a few suggestions.
In the OnSave function, get it to check whether or not the file has been saved yet -- if so, save as usual -- if not, start the SaveAs function instead (so that the document is not unknowingly giving the user a "noname.txt" name).
Make an OnNew function that starts a new document -- add it to the menu
Here's something I couldn't figure out how to do (newbie, remember?). For OnOpen and OnExit, first compare the contents of the TextCtrl to the saved file -- if they are the same (ie: document is unmodified), proceed as usual -- if not -- present a dialog asking whether the user would prefer to save first, and perform the required function -- then proceed as usual.
Get Small Editor to print the contents of TextCtrl out. That will force the developer to poke through Documentation! Haven't tried that one m'self yet, but I think I will now
The transition between part 2 and ChallengeDemos is a little bit too much of a jump, so I'd suggest continuing part 3 as you have with part 2... and focus on the placement of widgets, which is the next thing covered in Getting Started.
Well, that's about all I have to say. Good work so far guys.
-- Poprocks 2004-03-23 19:12:24
Challenge 2 was simple enough, took about 20 minutes.
-- Pharrisee 2021-09-21 23:36:41
I really love this challenge tutorial. I rewrote the editor in the 2.5 style (import wx). I also disabled the 'Save' and 'Save As' menuitems on startup. On 'Open' or on modification of the Textcontrol content I enable them.
-- RudySchockaert 2021-09-21 23:36:41
Thanks for providing this obstacle course; it's quite helpful for learning. It took about an hour more or less. I had two thoughts:
(1) Is it possible to get the Help menu to appear on the right side of the MenuBar?
(2) I added a cheesy little Set_Title() method so that when the user opens or saves a new file, the title bar updates to reflect the new file name.
-- JeffCagle 2021-09-21 23:36:41