[Tutor] Radiobuttons (two options out of 4)
alan.gauld at yahoo.co.uk
Fri Mar 3 14:42:58 EST 2017
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.
Author of the Learn to Program web site
Follow my photo-blog on Flickr at:
More information about the Tutor