[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:
   else:   # if a button is unchecked, re-enable all
       for butt in [butt1,butt2,butt3,butt4]:

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

Alan G
Author of the Learn to Program web site
Follow my photo-blog on Flickr at:

More information about the Tutor mailing list