I want to use a Kivy Switch to turn something on/off. I am trying to stick with: http://kivy.org/docs/api-kivy.uix.switch.html , but there is no .kv example.
I have the following code, abstracted to the problem.
main.py:
def PID_an_aus(self, instance, value):
if value is True:
do something
else:
do something else
kv File:
Switch:
on_active: root.PID_an_aus()
The GUI is working properly as long as I don't click on the switch. As soon as I click on the switch, the Programm closes without an error.
I feel a bit stupid right know, can someone enlighten me? Thanks in advance!
The function is deblared as...
def PID_an_aus(self, instance, value):
...but you call it with...
on_active: root.PID_an_aus()
The problem is that you didn't call it with any arguments, whereas you declared it to expect two.
You could instead do
on_active: root.PID_an_aus(self, self.active)
As soon as I click on the switch, the Programm closes without an error.
Is there really no traceback here? You should get a 'function received wrong number of arguments (expected 3 got 1)' or similar.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.