In this part of course, you will find how to make applications for desktop or mobile consisting of two or more different screens. There can be menus, tutorials, question-answer sessions or any other requirements that can be solved with multiple screens. We utilize ScreenManager shipped with kivy for this purpose. The code is:
#-*-coding:utf-8-*- from kivy.app import App from kivy.lang import Builder from kivy.uix.screenmanager import ScreenManager, Screen Builder.load_string(""" <GirisEkrani>: Button: text: "İleri" on_release: root.manager.current = root.manager.next() <KontrolEkrani>: Button: text: "Geri" on_release: root.manager.current = root.manager.previous() """) class GirisEkrani(Screen): pass class KontrolEkrani(Screen): pass class ekranApp(App): def build(self): root = ScreenManager() root.add_widget(GirisEkrani(name = "giris_ekrani")) root.add_widget(KontrolEkrani(name = "kontrol_ekrani")) return root if __name__ == "__main__": ekranApp().run()
Note that in this example only one file is used for both Kivy and Python file. You can use Builder.load_string to apply a Kivy design which is in a string to your Python code.
comments powered by Disqus