My program enters input on one screen, and then goes over and displays it in another. I want to make the condition that the screen changes only when the value is greater than the digit 0. My screen manager is defined in the kivy file. My question is how to use this command βroot.manager.current =" SecondScreen "in my state. I do not know how to do this. Or maybe there is a way to make a condition in a .kv file?
main.py
from kivy.app import App
from kivy.properties import StringProperty, NumericProperty, ObjectProperty
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.textinput import TextInput
from kivy.properties import StringProperty, NumericProperty, ObjectProperty
global var
global pp
pp = '0'
class FirstScreen(Screen):
global pp
ppp = StringProperty('')
def g(self, text):
global pp
if text.isdigit() and int(text) > 0:
pp = text
my test.kv file
ScreenManager:
id: screen_manager
FirstScreen:
id: screen1
name: "FirstScreen"
manager: screen_manager
SecondScreen:
id: screen2
name: "SecondScreen"
manager: screen_manager
<FirstScreen>:
text_input: text_input
FloatLayout:
id: fl1
canvas.before:
Color:
rgba: 0.1, 0.1, 0.1, 1
Rectangle:
pos: self.pos
size: self.size
TextInput:
id: text_input
text: root.ppp
multiline: False
size_hint_x: .4
size_hint_y: .1
pos_hint: {'x': .1, 'y': .20}
Button:
background_color: 0.2, 0.7, 1, 1,
font_size: root.width / 15
id: btn1
text: "Next"
on_press:
root.g(text_input.text)
root.manager.current = 'SecondScreen'
size_hint_x: .4
size_hint_y: .1
pos_hint: {'x': .5, 'y': .20}
<SecondScreen>:
on_enter: root.f()
FloatLayout:
id: fl2
canvas.before:
Color:
rgba: 0.1, 0.1, 0.1, 1
Rectangle:
pos: self.pos
size: self.size
Label:
color: 0.2, 0.7, 1, 1,
font_size: 15
id: lb1
text: root.idf
size_hint_y: .2
pos_hint: {'x': .1, 'y': .8}
source
share