[Tutor] Python GUI

Walter Prins wprins at gmail.com
Wed Jun 29 15:03:38 CEST 2011


Just to add to what Alan's said:  A key thing you will need to wrap your
head around when transitioning to GUI applications is the fact that the
application is then not linear (or as linear) as a console/text
application.

In a console application you basically control everything, and if there
needs to be a loop in the application to repeatedly collect user actions or
events (such as menu selections and so on) etc, then it's up to you to write
this yourself.

GUI applications are however different, in that the entire GUI system is
"event driven".  Conceptually what this means is that operating system is
ultimately responsible for collecting events (such as mouse clicks, keyboard
input, and so on) and it delivers these events/actions to your application
by sending it messages (which ultimately translates into functions and
methods in your application being called, as if by magic, from the
outside.)

The upshot of this is, as Alan said, that in most GUI applications you don't
write loops to "wait for input" yourself, you instead hand this off to the
operating system.   And it knows to call your methods by the fact that in
some part of your application you "register your interest" in receiving
various events, typically by providing an event handler (a method to be
called when that event happens.)

So conceptually, in a console application, you write the "main" loop
yourself, and directly call other methods/functions when certain "events"
happen (such as the user selecting a menu option.)  In a GUI application,
you can imagine this loop is somewhere inside the operating system (not
inside your application), and so your application doesn't provide one
itself, instead your application collaborates with the operating system to
make your application happen.  Object orientation conceptually is all about
objects collaborating with other objects by sending and receiving messages,
collectively working towards a solution.

Hope that helps.

Walter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110629/eb660662/attachment.html>


More information about the Tutor mailing list