python - Glade/GTK3 and radio buttons -
using tutorial https://python-gtk-3-tutorial.readthedocs.io/en/latest/builder.html have created similar glade gui has quit button , 2 radio buttons , b. quite confused radio buttons.
if use gtkbutton or gtktogglebutton rba function triggers twice, assume triggers both when button becomes active 1 , when becomes inactive one. right?
i don't need complicated, either
a function triggers when button clicked, within can find out 1 active, or
a function each button triggers when own button clicked.
i need able switch button active, preferably without triggering the/its function.
have misunderstood essential?
edit: after experimentation, have found second bit of code works signal gtktogglebutton>toggled>rba. can't similar work other button though!
import gi gi.require_version('gtk', '3.0') gi.repository import gtk class handler: def buttonquit(self, menuitem): # quit quit button gtk.main_quit() def on_window1_destroy(self, object): # close window 0 or x gtk.main_quit() def rba(self, menuitem): print('a') builder = gtk.builder() builder.add_from_file('test.glade') builder.connect_signals(handler()) window = builder.get_object("window1") window.show_all() gtk.main()
import gi gi.require_version('gtk', '3.0') gi.repository import gtk class handler: def buttonquit(self, menuitem): # quit quit button gtk.main_quit() def on_window1_destroy(self, object): # close window 0 or x gtk.main_quit() def rba(self, menuitem): print('in rba') print (rba.get_active()) builder = gtk.builder() builder.add_from_file('test.glade') builder.connect_signals(handler()) window = builder.get_object("window1") rba = builder.get_object('radiobuttona') window.show_all() gtk.main()
<?xml version="1.0" encoding="utf-8"?> <!-- generated glade 3.18.3 --> <interface> <requires lib="gtk+" version="3.12"/> <object class="gtkwindow" id="window1"> <property name="can_focus">false</property> <property name="window_position">center</property> <property name="gravity">center</property> <property name="has_resize_grip">true</property> <signal name="destroy" handler="on_window1_destroy" swapped="no"/> <child> <object class="gtkbox" id="box1"> <property name="visible">true</property> <property name="can_focus">false</property> <property name="orientation">vertical</property> <child> <object class="gtkbuttonbox" id="buttonbox1"> <property name="visible">true</property> <property name="can_focus">false</property> <property name="halign">center</property> <property name="valign">center</property> <property name="layout_style">start</property> <child> <object class="gtkradiobutton" id="radiobuttona"> <property name="label" translatable="yes">a</property> <property name="visible">true</property> <property name="can_focus">true</property> <property name="receives_default">false</property> <property name="halign">start</property> <property name="valign">center</property> <property name="xalign">0</property> <property name="active">true</property> <property name="draw_indicator">true</property> </object> <packing> <property name="expand">false</property> <property name="fill">false</property> <property name="position">0</property> </packing> </child> <child> <object class="gtkradiobutton" id="radiobuttonb"> <property name="label" translatable="yes">b</property> <property name="visible">true</property> <property name="can_focus">true</property> <property name="receives_default">false</property> <property name="halign">start</property> <property name="valign">center</property> <property name="xalign">0</property> <property name="draw_indicator">true</property> <property name="group">radiobuttona</property> </object> <packing> <property name="expand">false</property> <property name="fill">false</property> <property name="position">1</property> </packing> </child> </object> <packing> <property name="expand">false</property> <property name="fill">true</property> <property name="position">0</property> </packing> </child> <child> <object class="gtkbutton" id="buttonquit"> <property name="label" translatable="yes">quit</property> <property name="width_request">100</property> <property name="visible">true</property> <property name="can_focus">true</property> <property name="receives_default">true</property> <property name="halign">center</property> <property name="valign">center</property> <property name="xalign">0.56000000238418579</property> <property name="yalign">0.49000000953674316</property> <signal name="clicked" handler="buttonquit" swapped="no"/> </object> <packing> <property name="expand">false</property> <property name="fill">true</property> <property name="position">1</property> </packing> </child> </object> </child> </object> </interface>
this 1 of ways set python + gtk basic idea have. works me.
import gi gi.require_version('gtk', '3.0') gi.repository import gtk import sys class gui: def __init__ (self): builder = gtk.builder() builder.add_from_file('test.glade') builder.connect_signals(self) window = builder.get_object("window1") rba = builder.get_object('radiobuttona') rba.connect('toggled', self.rba) rbb = builder.get_object('radiobuttonb') rbb.connect('toggled', self.rbb) window.show_all() def buttonquit(self, menuitem): # quit quit button gtk.main_quit() def on_window1_destroy(self, window): # close window 0 or x gtk.main_quit() def rba(self, radiobutton): print('in rba') print (radiobutton.get_active()) def rbb(self, radiobutton): print('in rbb') print (radiobutton.get_active()) def main(): app = gui() gtk.main() if __name__ == "__main__": sys.exit(main())
Comments
Post a Comment