In Python's Gtk module, you can use Gtk.RadioButton.get_active()
to get whether the radio button is checked or not. However, I can't find any such method in Rust's equivalent, gtk::RadioButton
. When I try to use RadioButton.active()
, I get an error saying that the trait bounds were not satisfied for gtk::RadioButton
. I've tried searching get(
, active
, checked
, state
, and selected
in the docs, to no avail. This should be pretty self-explanatory, so I don't think I need to provide a code example. Does anyone know how to get the selected RadioButton
in Rust (ideally without using a callback)?
Asked
Active
Viewed 154 times
0

Sylvester Kruin
- 3,294
- 5
- 16
- 39
-
1I think it's `is_active`, – MaxPlankton Jan 22 '22 at 19:23
-
@JohnKoch Yes, it is, see the answer below. – Sylvester Kruin Jan 22 '22 at 20:04
1 Answers
1
If you look at the one-and-only official Gtk3 documentation, you'll see that RadioButton
does not define an active
property. Instead it is inherited from its base class ToggleButton
.
AIUI, in gtk-rs, functions and properties inherited are actually part of the associated interface, not of the type itself. So your property is ToggleButtonExt::is_active()
.
In theory your RadioButton
value implements IsA<ToggleButton>
so it also implements ToggleButtonExt
, and the is_active()
method should be readily available.
If it says that the trait is not in scope maybe you forgot the use gtk::prelude::*;
?

rodrigo
- 94,151
- 12
- 143
- 190
-
Of course, I should have though of using `is_active()`. I wonder why it didn't appear in my searches for `active`? Maybe it's because of the multiple levels of inherited traits. – Sylvester Kruin Jan 22 '22 at 19:07
-
1@SylvesterKruin: That search failure happened to me many times. Now I look for what I want in the regular Gtk3 docs, and once I know exactly what I'm looking for, I go to the rust doc page for that type, its *Ext trait and *ExtManual trait, if it exists. – rodrigo Jan 22 '22 at 19:09