python - Why isn't kv binding of the screen change working? -
i've defined 2 buttons: 1 in kv , 1 in python. located in different screens , used navigate between them. found strange button defined in python switched screen, while 1 defined in kv did not. perhaps i'm not accessing app
class method properly?
here code of issue:
from kivy.app import app kivy.lang import builder kivy.uix.screenmanager import screen, screenmanager kivy.uix.button import button builder.load_string(''' <myscreen1>: button: id: my_bt text: "back" on_release: app.back ''') class myscreen1(screen): pass class testapp(app): def here(self, btn): self.sm.current = "back" def back(self, btn): self.sm.current = "here" def build(self): self.sm = screenmanager() s1 = screen(name = "here") bt = button(text = "here", on_release = self.here) s2 = myscreen1(name = "back") #s2.ids['my_bt'].bind(on_release = self.back) self.sm.add_widget(s1) s1.add_widget(bt) self.sm.add_widget(s2) return self.sm testapp().run()
so if define switching function in kv (on_release
), can't go "here"
screen. if uncomment line in python , comment on_release: app.back
instead, works fine.
i'm pretty sure correct way access current app, since doesn't give me errors (which means method located)
that's subtle difference between kv , python: in kv have write callback function call (a python expression), in case:
on_release: app.back(self)
Comments
Post a Comment