#!/usr/bin/python
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk

def on_active(switch, *args):
    print("active: %s" % switch.get_active())
    # If the switch was set to active, unset it
    if switch.get_active():
        switch.handler_block_by_func(on_active)
        switch.set_active(False)
        switch.handler_unblock_by_func(on_active)

window = Gtk.Window()
switch = Gtk.Switch(active=False)
switch.connect('notify::active', on_active)

window.add(switch)
window.connect('delete-event', Gtk.main_quit)

window.show_all()
Gtk.main()
