问题
I am using Python 3 with gobject introspection for Gtk. How can I have more than one toggle button linked together so they behave similar to tabs or radiobuttons - e.g. one is selected by default, and when another is clicked
the previously active
one is de-selected.
I have tried using set_sensetive
, but that greys out the widget that it is applied on.
回答1:
Use set_active()
(or props.active
). Alternatively, you can create some Gtk.RadioButton
widgets and set draw_indicator
property to False
. In the latter case you can create radio groups in normal way, without custom handling.
回答2:
Use a Gtk.RadioButton and set draw indocator mode to False
button1 = Gtk.RadioButton("Product Codes")
button1.set_mode(False)
https://lazka.github.io/pgi-docs/Gtk-3.0/classes/ToggleButton.html#Gtk.ToggleButton.set_mode
Thx to:
- https://stackoverflow.com/a/15123955/1907997 and
- How can I link a set of toggle buttons like radio buttons?
回答3:
You listen to the toggle signals on the toggle button then call set_active()
on the other ones. You need to block the toggled signals while calling set_active()
so that you don't get into a loop.
来源:https://stackoverflow.com/questions/15120746/how-can-i-link-a-set-of-toggle-buttons-like-radio-buttons