Я только начинаю программировать с помощью менеджера экрана в Kivy. Я пытаюсь вызвать функцию «print_text ()» из файла .kv, когда нажимаю кнопку «Нажми меня!». Я называю это неправильно, как input.<function>?
или я делаю что-то не так с моим кодом Python?
Примечание: я могу переключать экраны.
import kivy
kivy.require('1.10.0') # replace with your current kivy version !
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.gridlayout import GridLayout
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.lang import Builder
Builder.load_string("""
<Manager>:
id: screen_manager
screen_one: screen_one
screen_two: screen_two
ScreenOne:
id: screen_one
name: "screen_one"
manager: screen_manager
ScreenTwo:
id: screen_two
name: "screen_two"
manager: screen_manager
<ScreenOne>:
GridLayout:
id: input
rows: 2
display: entry
orientation: "vertical"
spacing: 10
padding: 10
BoxLayout:
orientation: "horizontal"
Label:
text: "Input Your Text"
size_hint_x: 0.22
size_hint_y: 0.22
TextInput:
id: entry
size_hint_x: 0.78
size_hint_y: 0.22
BoxLayout:
orientation: "horizontal"
Button:
text: "Press Me!"
on_press:
input.print_text("Screen1:" + entry.text)
Button:
text: "SecondScreen"
on_press:
root.manager.transition.direction = "left"
root.manager.transition.duration = 1
root.manager.current = "screen_two"
<ScreenTwo>:
GridLayout:
id: input
rows: 2
display: entry
orientation: "vertical"
spacing: 10
padding: 10
BoxLayout:
orientation: "horizontal"
Label:
text: "What's in your Mind?"
size_hint_x: 0.22
size_hint_y: 0.22
TextInput:
id: entry
size_hint_x: 0.78
size_hint_y: 0.22
BoxLayout:
orientation: "horizontal"
Button:
text: "Press Me!"
on_press:
input.print_text("Screen2:" + entry.text)
Button:
text: "FirstScreen"
on_press:
root.manager.transition.direction = "right"
root.manager.transition.duration = 1
root.manager.current = "screen_one"
""")
class SampleScreen(GridLayout):
def print_text(self, text):
print text
class ScreenOne(Screen):
pass
class ScreenTwo(Screen):
pass
class Manager(ScreenManager):
pass
class SimpleApp(App):
def build(self):
return Manager()
myapp = SimpleApp()
myapp.run()
Заранее спасибо за помощь