I have two toggle buttons that I want to link together so that pressing one releases the other one. So my signals look like this
def on_btn1_tgl_clicked(self, widget, data=None):
toggled = not self.btn2_toggle.get_active()
self.btn2_toggle.set_active(toggled)
def on_btn2_tgl_clicked(self, widget, data=None):
toggled = not self.btn1_toggle.get_active()
self.btn1_toggle.set_active(toggled)
This seems to work just as I expect, except that when I run the code I get this error
Error in sys.excepthook:
RuntimeError
Original exception was:
RuntimeError
The buttons work fine and nothing crashes, but I don’t know why I’m getting the error, or what it means. If I don’t link the buttons I don’t get any errors.
Does anyone know how to fix this?
When I run your code, I get this exception :
RuntimeError: maximum recursion depth exceededand the buttons doesn’t work.My explication is :
When you click on button 1, it emit the
toggledsignal and execute youron_btn1_tgl_clicked()method.In this method, you use
gtk.ToggleButton.set_active()which emit atoggledsignal too that call youron_btn2_tg1_clicked()method which emit also atoggledsignal.So, we enter in infinite loop. That’s why the exception is raised.