Please if you like my content Please do not forget to support this channel on PayPal now for $1 only! Or less
from kivy.properties import ObjectProperty, StringProperty
try:
import os.path
import json
import pickle
from kivy.app import App
from kivy.lang.builder import Builder
from kivy.uix.widget import Widget
from kivy.uix.textinput import TextInput
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.screenmanager import Screen, ScreenManager
screenmanager = """
ScreenManager:
FirstScreen:
SecondScreen:
<FirstScreen>:
name: 'first'
RelativeLayout:
orientation:'vertical'
pos: self.pos
size: root.size
id: test2
Button:
text:'notepad'
on_press: root.manager.current = 'second'
<SecondScreen>:
name: 'second'
RelativeLayout:
orientation:'vertical'
pos: self.pos
size: root.size
id: test2
TextInput:
id:input
text: str(root.textinput)
pos_hint: {'center_x': 0.5, 'center_y': 0.705}
size_hint: 0.95, 0.5
Button:
text:'Menu'
size_hint:1,.2
on_press: root.manager.current = 'first'
on_press: root.print()
"""
class Switch(App):
def build(self):
screen = Builder.load_string(screenmanager)
return screen
class FirstScreen(Screen, BoxLayout):
if os.path.isfile("savedxx"):
print('file exists')
load = text = pickle.load(open("savedxx", "rb"))
textinput = StringProperty(load)
print(load)
else:
print("file does not exist")
textinput = StringProperty()
class SecondScreen(Screen, BoxLayout):
if os.path.isfile("savedxx"):
print('file exists')
load = text = pickle.load(open("savedxx", "rb"))
textinput = StringProperty(load)
print(load)
else:
print("file does not exist")
textinput = StringProperty()
def print(self):
text = self.ids.input.text
print(text)
text = pickle.dump(text, open("savedxx", "wb"))
sm = ScreenManager()
sm.add_widget(FirstScreen(name='first'))
sm.add_widget(SecondScreen(name='second'))
if __name__ == "__main__":
Switch().run()
except FileNotFoundError:
pass
No comments:
Post a Comment