How can I link a set of toggle buttons like radio buttons?

吃可爱长大的小学妹 提交于 2020-07-05 10:53:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!