I am trying to use the Dynamic Classes technique to format my code nicer, rather than have everything in one .kv
file. I look over this answer and tried to replicate it as best as I could to what I have, but am running into an issue.
The code works, but does not transition to the "select" screen once the password is entered correctly. Instead, the input text is cleared (as it should be), though does not transition. Almost as if the "select" screen is not properly linked. I am not sure where I am going wrong. Could someone provide me with some assistance?
main.py
from kivy.app import App
from kivy.lang.builder import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.popup import Popup
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.uix.boxlayout import BoxLayout
def invalid_login():
app = App.get_running_app()
app.root.current = "Main"
# Create a BoxLayout to add multiple lines or buttons to a PopUp
box = BoxLayout()
# Create PopUp
pop = Popup(
title="Invalid Password",
size_hint=(None, None), size=(200, 100),
content=box,
auto_dismiss=False
)
# Dismiss PopUp
box.add_widget(Button(text="Close", on_release=pop.dismiss))
pop.open()
class MainWindow(Screen):
def login(self):
if self.ids.password.text == "Password":
# Clear TextInput
self.ids.password.text = ""
# Go to the next page
app = App.get_running_app()
app.root.current = "Select"
else:
self.ids.password.text = ""
invalid_login()
class SelectWindow(Screen):
pass
class TrainingWindow(Screen):
pass
class ModelWindow(Screen):
pass
class TrainModelWindow(Screen):
pass
class ParametersWindow(Screen):
pass
class WindowManager(ScreenManager):
pass
kv_main = Builder.load_file('main.kv')
kv_select = Builder.load_file('select.kv')
kv_training = Builder.load_file('training.kv')
kv_model = Builder.load_file('model.kv')
kv_train_model = Builder.load_file('train_model.kv')
kv_parameters = Builder.load_file('parameters.kv')
class MyApp(App):
def build(self):
return kv_main
if __name__ == '__main__':
MyApp().run()
main.kv
#:import utils kivy.utils
#:include main.kv
#:include select.kv
#:include training.kv
#:include model.kv
#:include train_model.kv
#:include parameters.kv
MainWindow:
name: "Main"
GridLayout:
cols: 1
BoxLayout:
orientation: "vertical"
canvas.before:
Color:
rgba: 0,0,0,1
Rectangle:
pos: self.pos
size: self.size
Label:
size_hint: 1, 1
text: "App"
font_size: 50
color:
utils.get_color_from_hex('#FF0000')
Label:
size_hint: 1, 1
text: "This App Does...."
font_size: 40
BoxLayout:
size_hint: 1, 0.005
canvas.before:
Color:
rgba: (1,1,1,1)
Rectangle:
size: self.size
pos: self.pos
BoxLayout:
orientation: "horizontal"
size_hint: (0.35, 0.35)
padding: (0,0,25,0)
Label:
font_size: 20
text: "Password"
size_hint: (0.5, 0.35)
pos_hint: {'x': 1, 'y': 0.4}
background_color: (0,0,0,1)
canvas.before:
Color:
rgba: self.background_color
Rectangle:
size: self.size
pos: self.pos
TextInput:
id: password
multiline: False
size_hint: (0.5, 0.35)
pos_hint: {'x': 1, 'y': 0.4}
focus: True
background_color:
utils.get_color_from_hex('#18B8D9')
cursor_color: (0,0,0,1)
password: True
Button:
text: "Submit"
on_release: root.login()
select.kv
<SelectWindow@Screen>:
name: "Select"
BoxLayout:
orientation: "vertical"
Button:
text: "Go Back"
on_release:
app.root.current = "Main"
root.manager.transition.direction = "right"