1

As the title says, I am trying to print out the value of a Switch widget every time the value is changed. I have managed to write the callback itself, but I can't seem to figure out what arguments to pass the callback in my .kv file.

Right now I get the error that: 'callback() takes exactly 2 arguments (1 given)'

from kivy.config import Config
Config.set('graphics', 'width', '600')
Config.set('graphics', 'height', '300')
Config.set('graphics', 'resizable', 0)
from kivy.app import App
from kivy.uix.tabbedpanel import TabbedPanel
from kivy.uix.boxlayout import BoxLayout
from kivy.lang import Builder
from kivy.properties import ObjectProperty
from kivy.uix.switch import Switch

Builder.load_file('hueLayout.kv')

class hueLayout(BoxLayout):
    pwr1_switch = ObjectProperty()


    def callback(instance, value):
        print 'instance: ', instance
        print 'value: ', value


    #pwr1_switch.bind(pwr1_switch, active=callback)

class HueController(App):
    def build(self):
        #self._app_window_size = 5, 20
        return hueLayout()

if __name__ == '__main__':

    Config.write()
    HueController().run()

<hueLayout>:
    #size_hint: .5, .5
    #pos_hint: {'center_x': .5, 'center_y': .5}
    #height: '200dp'
    #width: '100dp'
    pwr1_switch: pwr1_input

    TabbedPanel:
        do_default_tab: False

        TabbedPanelItem:
            text: 'Master'
            GridLayout:
                cols: 3

                Switch:
                    id: pwr1_input
                    active: root.callback()



        TabbedPanelItem:
            text: 'Light 1'
            BoxLayout:

        TabbedPanelItem:
            text: 'Light 2'

        TabbedPanelItem:
            text: 'Light 3'

Thanks

4

1 に答える 1