Disable RadioButton

Hi, everyone

items_to_disable = ["Mild steel", "4140"]

for rb in self.radiobuttonlist.Children:
    if isinstance(rb, Eto.Forms.RadioButton):
        if rb.Text in items_to_disable:
            rb.Enabled = False

the posted code is taken from the file shared by Clement, used to disable RadioButton from radiobuttonlist

it would be possible to have the same result, without having to use the for loop and the two if?

thanks for the answer (if there is an answer)

Hi @0904, why you would like to do this ? Just curious.


Hi @clement,

first of all, thanks for the code you posted,
I could use your own word: curiosity

but besides this, being at the beginning in the use of RCommon and Eto, I’d like to understand how this type of object is structured, learn to use them in the best way and not simply by picking up parts of the codes, but being aware of what I’m doing to do. (if it can be done)

I have the thesis that Children objects are containers, and I would like to understand how to interact with the elements of this container

ps obviously for something wrong I said, correct me.

Hi @0904, i’ll try to explain in the context of the linked example.

The RadioButtonList is a container as it derives from the Container class. It contains other items or controls, like eg. RadioButton. Children can be containers too, so basically a Form or Dialog does have multiple child controls (like a RadioButtonList or a Panel) which intself can also have children.

The reason for the for loop and the if statements in the code example is, we need to iterate over the children of the RadioButtonList and only are interested in children of type RadioButton using:

for rb in self.radiobuttonlist.Children:
    if isinstance(rb, Eto.Forms.RadioButton):

then, when we’re sure that we are iterating over an item of type RadioButton, we’re checking if it’s Text property equals one of the strings in the list items_to_disable. Note that a RadioButton is also a subclass from the TextControl class which has the property Text. The easiest is to look at the “Inheritance Hierarchy” of the RadioButton.

To finally set the Enabled state of the RadioButton, we change the Enabled property of the Control. Note that RadioButton is also a sub-class of Control which has this Enabled property.

does this help ?


Hi @clement,
Thanks for the reply,

I agree with everything you said, in fact I’ve been on this topic for a couple of days, and let’s say that everything you explained about execution was clear to me that the first if of the for loop is used to exclude DynamicLayout while the second if is used to retrieve the item with the same text as the items_to_disable list. but what I disagree with (it will be my limit) if I already know which Button to disable and as we said RadioButtonList is a container, does it have a list with indexes or something like a dictionary that these elements are placed in the Button it contains? being a container, I would like to understand what kind of container it is to know with which tools I can work with it, I hope I explained myself.

ex: if it’s a list, I work with indexes to get the values
if instead it is a dictionary I work with Key to get the values
or is it a totally different container from the ones mentioned?

I hope I’m not using your patience
(and sorry for the translation)

sending to print self.radiobuttonlist.Children
I get this string:

<Eto.Forms.Container+<get_Children>d__10 object at 0x000000000000002B [Eto.Forms.Container+<get_Children>d__10]>

I think by understanding how to interact with this object, one could directly disable the desired Button element

I guess it depends on how you have added the RadioButton items to the RadioButtonList. In above linked example script, the radio buttons are just added using a DataStore and this builds the radio button controls for you.

You can also disable the same two radio buttons like below, it first gets only the list of radio buttons from the Controls of the RadioButtonList and then accesses them by index:

def DisableRadioButtonListItems(self, sender, e):
    # get children except the first (the DynamicLayout)
    radio_buttons = list(self.radiobuttonlist.Children)[1:]
    # disable by index (but get index from name)
    radio_buttons[self.radiobuttonlist.DataStore.IndexOf("Mild steel")].Enabled = False
    radio_buttons[self.radiobuttonlist.DataStore.IndexOf("4140")].Enabled = False

what i do not understand so far is that i cannot access the Items property of the self.radiobuttonlist control. Trying to this:

print self.radiobuttonlist.Items

gives this (translated) error:

Message: Object of type “IronPython.Runtime.List” cannot be converted in “Eto.Forms.ListItemCollection”

Maybe @curtisw can explain this. Seems to be an IronPython thing i guess…



I’ve tried almost every property and if I’m not mistaken there are several that cannot be accessed

wonderful solution :clap:

if I understand correctly you have inserted the container into a list, and at that point it is possible to manage the elements of the container with the indexes of the list

Great Great :+1:

for this reason I also try to find alternative solutions by asking myself these questions, because I would never have thought of a similar solution, and certainly this approach can be useful by applying it in various situations

last thing, how can I disable a Button already at the beginning of the Forms, inside __ init __ it gives me error. . .

self.TestButton= Eto.Forms.Button(Text="MyButton", Enabled=False)


sorry @clement :pray:

i mean how to disable a radiobuttonlist button

i had tried like this:

self.radiobuttonlist.Enabled = [True, False, True]

but it does not work :man_facepalming: :man_facepalming:

Hi @0904, enabled and disabled usually refers to the accessability of the radio button as shown in above example script. Do you mean how to make one selected ? If so, there can only be one selected which is done by setting the SelectedIndex or SelectedValue property or by clicking on it.


Hi @clement thanks for reply

I mean, when the form appears, I would like to disable one of the radiobuttonlist buttons, just like when I click on the DisableRadioButtonListItems button

        #self.radiobuttonlist.Enabled = False
        radio_buttons = list(self.radiobuttonlist.Children)[1:]
        #print radio_buttons
        radio_buttons[self.radiobuttonlist.DataStore.IndexOf('4140')].Enabled = False
        self.Content = layout
    def DisableRadioButtonListItems(self, sender, e):
        #'''disables items in a radiobuttonlist'''
        radio_buttons = list(self.radiobuttonlist.Children)[1:]
        radio_buttons[self.radiobuttonlist.DataStore.IndexOf('4140')].Enabled = False

basically your codes work inside the click event of the button,
but if I put it in the __ init __ constructor I get an error

if instead I remove the hashtag from self.radiobuttonlist.Enabled = False this line works
but it disables me all buttons from the list radiobuttonlist, while I’m interested in one

I started a print on radio_buttons and I get an empty list. I guess at that stage it doesn’t load the objects yet


here I would like to have a situation like this when starting the forms:


without having to click on the button DisableButtons

Hi @0904, just add below to the end of your init function:

self.Content = layout
self.LoadComplete += self.DisableRadioButtonListItems


1 Like

lo and behold, I had tried to call event at the end of init but failed, so this was the correct syntax :+1:

thank you very much Clement, for all the support given :pray:

1 Like