def show_plugins(self, plugins_list): def on_active(sw, value): self.plugins.toggle_enabled(self.electrum_config, sw.name) run_hook('init_kivy', self) for item in self.plugins.descriptions: if 'kivy' not in item.get('available_for', []): continue name = item.get('__name__') label = Label(text=item.get('fullname'), height='48db', size_hint=(1, None)) plugins_list.add_widget(label) sw = Switch() sw.name = name p = self.plugins.get(name) sw.active = (p is not None) and p.is_enabled() sw.bind(active=on_active) plugins_list.add_widget(sw)
from kivy.app import App from kivy.uix.boxlayout import BoxLayout from kivy.uix.switch import Switch from var import var layout = BoxLayout() switch = Switch(text="setting") if var == 0: switch.active = False elif var == 1: switch.active = True layout.add_widget(switch) def fun(x, y): if y == True: f = opne("var.py", "w") switch.bind(active=fun) class MyApp(App): def build(self): return layout if __name__ == "__main__": MyApp().run()