Kivy: Changing screens in screen manager with an on_press event

后端 未结 3 1034
旧时难觅i
旧时难觅i 2020-12-10 14:55

I would like to know how to change screens using an on_press event binded to a button, without using a KV file/KV language.

I have read through the Kivy documentatio

3条回答
  •  北海茫月
    2020-12-10 15:40

    Another solution, was to use the setter method of EventDispatcher, to get a reference to the setter function for screen_manager.current

    button.bind(on_press=partial(sm.setter('current'), (sm, 'whatever'))
    

    of course, it's not very sexy, that's why kv is often a cleaner solution to these things, but it should work.

    ps: in case you don't know about it, partial comes from the functools module, and it's often useful to build these kind of callbacks with a preloaded parameter.

提交回复
热议问题