I want to select an object from a class Screen, while in App class.
I wrote a command that I want to execute, but it doesn't work in the code. I want the code to fire when the application is closed.
main.py:
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
class Screeen(Screen):
pass
class Manager(ScreenManager):
pass
kv = Builder.load_file("plann.kv")
class Ball(App):
#def on_stop(self):
#print(Screeen.ids.textinput.text)
def build(self):
return kv
if __name__ == "__main__":
Ball().run()
plann.kv:
Manager:
Screeen:
<Screeen>:
name: "Screeen"
textinput: textinput
FloatLayout:
size: root.width, root.height
TextInput:
id: textinput
text: "hi"
size_hint: (.45, .1)
pos: root.width * 1 / 3 , root.height * 1 / 2
here is a tested and working example. The idea is to keep a reference to your top-level (root) widget in your init of the app so you can reference it later.
I changed the .kv file to a string just to make this an easier one-file test. The use of a .kv file is a good idea so you can just make that little adjustment in your project.