[Tutor] Radiobuttons (two options out of 4)

Pooja Bhalode poojabhalode11 at gmail.com
Fri Mar 3 15:59:09 EST 2017


Hi Alan,

Thank you for letting me know.
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:
check1butt.config(state = 'disabled')
check2butt.config(state = 'disabled')
check3butt.config(state = 'disabled')
check4sbutt.config(state = 'disabled')

Label(lom, text = "Choose two options from:").grid(row = 9, column = 1,
sticky = W)
check1butt = Checkbutton(lom, text = "A-optimality", variable = check1)
check1butt.bind("<Button-1>", selfcheck)
check1butt.grid(row = 10, column = 1, sticky = W)
check2butt = Checkbutton(lom, text = "D-optimality", variable = check2)
check2butt.bind("<Button-1>", selfcheck)
check2butt.grid(row = 11, column = 1, sticky = W)

check3butt = Checkbutton(lom, text = "E-optimality", variable = check3)
check3butt.bind("<Button-1>", selfcheck)
check3butt.grid(row = 12, column = 1, sticky = W)

check4butt = Checkbutton(lom, text = "Parameter Co-Variance", variable =
check4)
check4butt.bind("<Button-1>", selfcheck)
check4butt.grid(row = 13, column = 1, sticky = W)
if check1.get() == 1:
if check2.get() == 1:
check3butt.config(state = 'disabled')
check4butt.config(state = 'disabled')

But here, I have the problem where I do not know how to design the function
selfcheck. Here, the function should disable the rest of the checkbuttons
which are not selected after two options are selected by the user. Can you
please let me know how to design the function?
Thank you

Pooja

On Fri, Mar 3, 2017 at 2:42 PM, Alan Gauld via Tutor <tutor at python.org>
wrote:

> On 03/03/17 16:43, Pooja Bhalode wrote:
>
> > I am trying to create a GUI with four options out of which the user is
> > supposed to select two. But once the user selected two out of those four
> > options, the others need to get greyed out at that instant.
> >
> > I tried the following thing:
> >
> > *Label(lom, text = "Choose two options from:").grid(row = 9, column = 1,
> > sticky = W)*
> > * check1butt = Checkbutton(lom, text = "A-optimality", variable =
> > check1).grid(row = 10, column = 1, sticky = W)*
> > * check2butt = Checkbutton(lom, text = "D-optimality", variable =
> > check2).grid(row = 11, column = 1, sticky = W)*
> > * check3butt = Checkbutton(lom, text = "E-optimality", variable =
> > check3).grid(row = 12, column = 1, sticky = W)*
> > * check4butt = Checkbutton(lom, text = "Parameter Co-Variance", variable
> =
> > check4).grid(row = 13, column = 1, sticky = W)*
> > * if check1.get() == 1:*
> > * if check2.get() == 1:*
> > * check3butt.config(state = 'disabled')*
> > * check4butt.config(state = 'disabled')*
>
> The problem is you are not thinking about this in an event driven way.
> The two if statements are only ever executed once when you create the
> GUI, they are never used again.
>
> What you need to do is create an event handler that will check how
> many buttons are checked and if it is 2 set the unchecked buttons to
> disabled. Then bind that event handler to all four buttons.
>
>
> --
> 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
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>


More information about the Tutor mailing list