from kivy.uix.gridlayout import GridLayout
from kivy.app import App
from kivy.properties import StringProperty
class Check(GridLayout):
Status = StringProperty("Begin State")
Status1 = StringProperty("Begin ToggleButton")
def checkActive(self, *args):
if args[1]:
self.Status = "Device On"
print("Turning On")
else:
self.Status = "Device Off"
print("Turning Off")
def checkActive1(self, *args):
if args[1]:
self.Status3 = "Devide On"
print("Turning On")
else:
self.Status3 = "Device Off"
print("Turning Off")
class Check_forumApp(App):
def build(self):
self.title = "Checkboxes and Buttons"
return Check()
if __name__ == '__main__':
Check_forumApp().run()
<Check>:
cols: 3
canvas:
Color:
rgb: .2,.2,.2
Rectangle:
pos: self.pos
size: self.size
Label:
text: 'A checkbox'
CheckBox:
on_active: root.checkActive(*args)
Label:
text: root.Status
Label:
text: 'Toggle Button'
ToggleButton:
text: 'ToggleButton'
active: True
on_press: root.checkActive1(*args)
Label:
text: root.Status1
on_press: root.checkActive1(*args)
to
on_active: root.checkActive1(*args)
That not what you are looking for?
Cheers
on_active: root.checkActive1(*args)
...
18: text: 'Toggle Button'
19: ToggleButton:
>> 20: on_active: root.checkActive1(*args)
21: text: 'ToggleButton'
22: Label:
...
KeyError: 'active'
on_state: root.checkActive1(*args)
Hmm, on_state: root.checkActive1(*args)
is better, works without errors, but not switching states.
kivy:
Label:
text: 'Toggle Button'
ToggleButton:
on_state: root.checkActive1(*args)
text: 'ToggleButton'
Label:
text: root.Status1
Python:
def checkActive1(self, *args):
if args[1]:
self.Status1 = "Device On"
print("Turning On")
else:
self.Status1 = "Device Off"
print("Turning Off")
Terminal (clicking on ToggleButton):
Turning On
Turning On
Turning On
Turning On
Turning On
and Status1 is only "Device On".
Checkbox switching states normally, but i don't know, why ToggleButton, not...
def checkActive1(self, *args):
print "args=" + str(args)
if args[1]: ....
You might find that you need to used args[0]?Hi ZenCODE,
python:
def checkActive1(self, *args):
print ("args=" + str(args))
if args[0]:
self.Status1 = "Device On"
print("Turning On")
else:
self.Status1 = "Device Off"
print("Turning Off")
terminal:
args=(<kivy.uix.togglebutton.ToggleButton object at 0x7f19828c0ca8>, 'down')
Turning On
args=(<kivy.uix.togglebutton.ToggleButton object at 0x7f19828c0ca8>, 'normal')
Turning On
args=(<kivy.uix.togglebutton.ToggleButton object at 0x7f19828c0ca8>, 'down')
Turning On
args=(<kivy.uix.togglebutton.ToggleButton object at 0x7f19828c0ca8>, 'normal')
Turning On
args=(<kivy.uix.togglebutton.ToggleButton object at 0x7f19828c0ca8>, 'down')