[Tutor] Alternate button hit problem in tkinter

Alan Gauld alan.gauld at btinternet.com
Wed Feb 2 02:02:58 CET 2011


"Wayne Werner" <waynejwerner at gmail.com> wrote 

> def one_or_zero():
>    x = 0
>    while True:
>        x = not x
>        yield x

In case its not obvious how this iis used in a GUI context...

So for your exampler crweate a state variable somewhere 
in your GUI (x in Waynes example) and toggle its value 
from your button handler and return the result.

The easiest way to do that is to use a single function, 
like Wayne's, and call it from all of your handlers.

HTH

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/




More information about the Tutor mailing list