[Tutor] Radiobuttons (two options out of 4)

Alan Gauld alan.gauld at yahoo.co.uk
Fri Mar 3 20:17:40 EST 2017


On 03/03/17 20:59, Pooja Bhalode wrote:

> I tried putting in the event handlers for the checkbuttons as shown below.
> 
> num = 0
> def selfcheck(event):
>      print "Self Check"
>      num = num + 1
>      if num == 2:

You need num to be inside the function since it needs
to be reset to zero on every check.

And the increment should only be if the button
is checked. Something like(untested pseudo-code)

def selfcheck(evt):
   num = 0
   for butt in [butt1,butt2,butt3,butt4]:
       if butt.isChecked:
          num += 1

   if num == 2
      for butt in [butt1,butt2,butt3,butt4]:
         if not butt.isChecked:
            butt.disable()
   else:   # if a button is unchecked, re-enable all
       for butt in [butt1,butt2,butt3,butt4]:
          butt.enable()

You then need to bind that to the mouse click event
for each button.


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list