'Save data from TextInput in Kivy Python
Firstly I'd like to thank every single one of you for being part of this wonderful community.
EDIT: The app allows the user to create and delete TextInputs similar to a "To Do List". I want the app to be able to keep the created widgets (TextInputs) and its contents (Text) after closing and re opening it.
My question is the following. I wish to be able to save/load the TextInput Widgets created and the information in them thus allowing the user to open the app and keeping the info. You do not need to give me the finished code, with a small hint on where to look or how to approach the matter would be very much appreciated!
Here is a simplified version of the code.
main.py
from kivy.app import App
from kivy.uix.image import Image
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.button import Button, ButtonBehavior
from kivy.factory import Factory as F
from kivy.properties import NumericProperty
from kivy.lang import Builder
class WindowManager(ScreenManager):
pass
class MainWindow(Screen):
pass
class SecondWindow(Screen):
pass
class CButton(ButtonBehavior, Image):
pass
kv = Builder.load_file("my.kv")
class DisApp(App):
number = NumericProperty()
timer = None
cont_id = None
def build(self):
return kv
def create_task(self,instance):
print(instance.text)
if instance.text == "1":
self.root.get_screen("second").ids.container_1.add_widget(F.Task())
elif instance.text == "2":
self.root.get_screen("second").ids.container_2.add_widget(F.Task())
elif instance.text == "3":
self.root.get_screen("second").ids.container_3.add_widget(F.Task())
if __name__ == "__main__":
DisApp().run()
my.kv
#:import Factory kivy.factory.Factory
WindowManager:
MainWindow:
SecondWindow:
<Task@GridLayout>:
cols: 2
TextInput:
size_hint_x: 1
size_hint_y: None
size: (2, dp(40))
Button:
text: 'remove'
on_press: root.parent.remove_widget(root)
size_hint_x: .15
size_hint_y: None
size: (.5, dp(40))
<MainWindow>:
name: "main"
BoxLayout:
Button:
text: "press me"
on_release:
app.root.current = "second"
<SecondWindow>:
name: "second"
BoxLayout:
orientation: "vertical"
Accordion:
orientation: "vertical"
AccordionItem:
title: "ONE"
BoxLayout:
orientation: "vertical"
Button:
text: "1"
on_release: app.create_task(self)
ScrollView:
do_scroll_x: False
do_scroll_y: True
GridLayout:
size: (root.width, root.height)
id: container_1
cols: 1
size_hint_x: None
size_hint_y: dp(40)
height: self.minimum_height
row_default_height: 40
row_force_default: True
AccordionItem:
title: "TWO"
BoxLayout:
orientation: "vertical"
Button:
text: "2"
on_release: app.create_task(self)
ScrollView:
do_scroll_x: False
do_scroll_y: True
GridLayout:
size: (root.width, root.height)
id: container_2
cols: 1
size_hint_x: None
size_hint_y: dp(40)
height: self.minimum_height
row_default_height: 40
row_force_default: True
AccordionItem:
title: "THREE"
BoxLayout:
orientation: "vertical"
Button:
text: "3"
on_release: app.create_task(self)
ScrollView:
do_scroll_x: False
do_scroll_y: True
GridLayout:
size: (root.width, root.height)
id: container_3
cols: 1
size_hint_x: None
size_hint_y: dp(40)
height: self.minimum_height
row_default_height: 40
row_force_default: True
Button:
size_hint: (1,.15)
text: "back"
on_release:
app.root.current = "main"
root.manager.transition.direction = "right"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
