Login System in Kivy
12,036
You must create a method that I get the texts and do the verification. This method should be called when the button is pressed. If the credentials are correct you must change the Screen.
*.py
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.lang.builder import Builder
class LoginPage(Screen):
def verify_credentials(self):
if self.ids["login"].text == "username" and self.ids["passw"].text == "password":
self.manager.current = "user"
class UserPage(Screen):
pass
class ScreenManagement(ScreenManager):
pass
kv_file = Builder.load_file('login.kv')
class LoginApp(App):
def builder(self):
return kv_file
if __name__ == '__main__':
LoginApp().run()
*.kv
ScreenManagement:
LoginPage:
UserPage:
<LoginPage>:
name: "login_page"
BoxLayout:
TextInput:
id: login
TextInput:
id: passw
password: True # hide password
Button:
text: "go"
on_release: root.verify_credentials()
<UserPage>:
name: "user"
Button:
text: "back"
on_release: app.root.current = "login_page"
Author by
Michael
Updated on June 15, 2022Comments
-
Michael almost 2 years
I am new to Kivy, and I want to create a simple login system for desktop app.
Here's my python code:
class LoginPage(Screen): pass class UserPage(Screen): pass class ScreenManagement(ScreenManager): pass kv_file = Builder.load_file('login.kv') class LoginApp(App): def builder(self): return kv_file LoginApp().run()
and kivy file
ScreenManagement: LoginPage: UserPage: <LoginPage>: name: "login_page" BoxLayout: TextInput: id: login TextInput: id: passw Button: text: "go" on_release: app.root.current = "user" <UserPage>: name: "user" Button: text: "back" on_release: app.root.current = "login_page"
I want it to change the screen only if text in form is what I need (e.g - TextInput(login) = 'username', TextInput(pass) = 'password').
I know I need to write a method for this, but I need help with this.
-
Juggernaut about 6 years
screen_manager.switch_to(Screen())
-