[Tutor] program hangs in while loop using wx.yield

Walter Prins wprins at gmail.com
Mon Nov 15 02:59:43 CET 2010


On 15 November 2010 00:12, Alex Hall <mehgcap at gmail.com> wrote:

> Again: is there a basic tutorial that would explain how control works
> when dealing with a gui, especially one that is meant to last a long
> time but occasionally block input?
>

Normally the way is for the GUI controls (e.g. widgets, grids, objects
whatever you want to call them) to ignore messages (e.g. clicks or keyboard
input or whatever).  To achieve this one can either use
properties/methods/behaviours already available on the widgets being used
(e.g. Buttons have an "Enabled" property that allows you to control whether
they're clickable or not), or you have to implementsuch behaviour yourself,
using some flag/state variables in your application.

As a tiny example, see here: http://pastebin.com/LqJkwpwA

As you can see, each time one of the buttons are clicked, the click handler
alters the buttons' enabled properties which ensures that only the other one
will be clickable next.  This example obviously sidestepped tracking "who's
turn it is" explicitly by directly flipping the Enabled state on the 2
buttons.  In your app I would suppose it'd be better to be explicit about it
and have variables to store this type of information, which can then refer
to in order to decide what to do inside your event handlers.

HTH,

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


More information about the Tutor mailing list