[英]How to send input between screens in kivy?
how can I send input from one screen to another screen.In class Create I set input2 to ObjectProperty.I just want to send that input2 to screen All, that I can set input2 to ObjectProperty in screen All.Is there some library or function to do it................................................................................................................................................................................................................................. Thanks My python file:如何将输入从一个屏幕发送到另一个屏幕。在 class 创建中,我将 input2 设置为 ObjectProperty。我只想将该 input2 发送到屏幕 All,我可以在屏幕 All 中将 input2 设置为 ObjectProperty。是否有一些库或 function去做.................................................. ..................................................... ..................................................... ..................................................... ................................感谢我的 python 文件:
Builder.load_file("main.kv")
db = TinyDB("storing.json")
from kivy.core.window import Window
Window.size=(400,600)
Window.clearcolor = (214/255, 201/255, 78/255, 1)
class MainWindow(Screen, FloatLayout):
def submit(self):
self.manager.current = "all"
class Create(Screen, FloatLayout):
input1 = ObjectProperty(None)
input2 = ObjectProperty(None)
def __init__(self, **kwargs):
super(Create, self).__init__(**kwargs)
self.text_store = JsonStore('storing.json')
print('loading...')
def give(self):
self.text_store['1'] = {self.input2.text:self.input1.text}
class All(Screen,FloatLayout):
def __init__(self, **kwargs):
super(All, self).__init__(**kwargs)
self.text_store = JsonStore('storing.json')
class Notes(App):
title = "NOTES"
def build(self):
sm = ScreenManager()
sm.add_widget(MainWindow(name="main"))
sm.add_widget(Create(name="create"))
sm.add_widget(All(name="all"))
return sm
if __name__ == "__main__":
Notes().run()
My kv.我的kv file:
文件:
<MainWindow>:
name:"main"
canvas:
Color:
rgba : 255,255,255,1
RoundedRectangle:
pos:(95, 450)
size : 210,120
radius: [30, 30, 30, 30]
FloatLayout:
Label:
text:"NOTES"
pos:(100,450)
size_hint:(.5,.2)
color:0,0,0,1
Button:
text:"NEW NOTE"
pos :(100, 300)
size_hint : (.5,.2)
on_release:app.root.current="create"
Button:
text:"ALL NOTES"
pos :(100, 180)
size_hint : (.5,.2)
on_release:app.root.current="all"
Button:
text:"EXIT"
pos :(100, 60)
size_hint : (.5,.2)
on_release:app.stop()
<Create>:
name:"create"
input1 : input1
input2 : input2
FloatLayout:
Label:
text:"NOTE NAME:"
pos_hint:{"x":0.07,"top":.95}
size_hint : (.1,0.05)
TextInput:
id : input1
multiline:True
pos_hint :{"x":.1,"top":.8}
size_hint : (.8,.4)
on_text:
root.give()
TextInput:
id:input2
multiline : False
pos_hint:{"x":.25,"top":.95}
size_hint:(.4,0.05)
Button:
id:"submit"
text:"SUBMIT"
pos_hint :{"x":.25,"top":.4}
size_hint : (.5,.2)
on_release:
app.root.current="all"
Button:
id:"back"
text:"BACK"
pos_hint :{"x":.25,"top":.2}
size_hint : (.5,.2)
on_release:app.root.current="main"
<All>:
FloatLayout:
Button:
text:"back"
size_hint:(1,.2)
pos_hint:{"x":0,"top":.2}
on_release:app.root.current="main"
You can grab the TextInput
info when the All
Screen
is displayed by adding an on_enter()
method, like this:您可以通过添加
All
on_enter()
方法在显示Screen
时获取TextInput
信息,如下所示:
class All(Screen,FloatLayout):
def __init__(self, **kwargs):
super(All, self).__init__(**kwargs)
self.text_store = JsonStore('storing.json')
def on_enter(self, *args):
self.ids.lab.text = self.manager.get_screen('create').input2.text
Just to display the transferred text, I added a Label
to the All
Screen
:只是为了显示传输的文本,我在
All
Screen
中添加了一个Label
:
<All>:
FloatLayout:
Button:
text:"back"
size_hint:(1,.2)
pos_hint:{"x":0,"top":.2}
on_release:app.root.current="main"
Label:
id: lab
text: 'None'
size_hint: .1, .1
pos_hint: {'center_x':0.5, 'top':1}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.