You see, I'm doing an indicator for Ubuntu and I wanted to implement a Preferences window. Since I have no idea about Python, after a lot of effort and a lot of reading of documentation I have managed to create a small window such that:
So far everything is correct. Now I have managed to receive the values of the switch and show them by console as "on" and "off".
Here comes my problem, which I do not know how to define . This is what I have code.
def __init__(self):
[...]
label11 = Gtk.Label('Autoarranque:')
label11.set_alignment(0, 0.5)
table11.attach(label11, 0, 1, 0, 1, xpadding=5, ypadding=5)
self.switch1 = Gtk.Switch()
self.switch1.connect("notify::active", self.on_switch_activated)
self.switch1.set_active = True
table11.attach(self.switch1, 1, 2, 0, 1,
xpadding=5,
ypadding=5,
xoptions=Gtk.AttachOptions.SHRINK)
[...]
def on_switch_activated(self, switch1, gparam):
if switch1.get_active():
state = "on"
return state
else:
state = "off"
return state
print("Switch ", state)
def close_ok(self):
stat = on_switch_activated(self, switch1, gparam)
print(stat)
Well, when you throw this, it returns an error within close_ok
that says NameError: global name 'on_switch_activated' is not defined
. Is not it supposed to be defined? If someone can explain it to me, I would appreciate it.
Greetings!