Looking for a basic GUI tutorial

Achim Domma achim.domma at syynx.de
Tue May 6 11:43:50 EDT 2003


"Russ Schmidt" <SchmidtRW at y12.doe.dov> wrote in message
news:Xns937371E52A7C8RWSBWXTY12DOEGOV at 160.91.22.101...
> I have tried John Grayson's "Python and Tkinter Programming", but that
book
> had me nearly screaming in frustration at it's lack of explanation. It
> tells me that a mainloop is necessary to start the Tkinter event loop, but
> there is no discussion about what an event loop is, or how it works, or
why
[...]

If you develop GUI apps, you have to think a little bit different about
programm flow. There is no predefined way through you code. You set up you
window and wait for user actions. 'Waiting for user action' means entering
this magic event loop. The GUI system captures user actions (key or button
pressed, value of some field changed, mouse moved, ...) and dispatches it to
the approriate window. In my Win32/C days you had to write something like
this (Pseudocode):

while(event = getNextEvent()) {
    switch( event.type ) {
         case BUTTON_PRESSED: ...;
         case SOME_OTHER_EVENT: ...;
    }
}

Your app has to ask the GUI system for the next event his window. Then it
has to check what kind of event occured and execute some approriate code.
These switch statements are today replaced by OO Programming. BUTTON_PRESSED
is dispatched to OnButtonPressed automatically (the default implementation
does nothing). Knowing this, the tutorial on the wxPython page should be
quite easy to understand.

I hope my english was understandable and was of some help.

regards,
Achim






More information about the Python-list mailing list