Last active
April 15, 2025 18:47
-
-
Save Cheaterman/812203a74f8c552a4918 to your computer and use it in GitHub Desktop.
Kivy Login example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*.pyc |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Connected>: | |
BoxLayout: | |
orientation: 'vertical' | |
Label: | |
text: "You are now connected" | |
font_size: 32 | |
Button: | |
text: "Disconnect" | |
font_size: 24 | |
on_press: root.disconnect() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from kivy.app import App | |
from kivy.uix.screenmanager import Screen, SlideTransition | |
class Connected(Screen): | |
def disconnect(self): | |
self.manager.transition = SlideTransition(direction="right") | |
self.manager.current = 'login' | |
self.manager.get_screen('login').resetForm() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#:include connected.kv | |
<Login>: | |
BoxLayout | |
id: login_layout | |
orientation: 'vertical' | |
padding: [10,50,10,50] | |
spacing: 50 | |
Label: | |
text: 'Welcome' | |
font_size: 32 | |
BoxLayout: | |
orientation: 'vertical' | |
Label: | |
text: 'Login' | |
font_size: 18 | |
halign: 'left' | |
text_size: root.width-20, 20 | |
TextInput: | |
id: login | |
multiline:False | |
font_size: 28 | |
BoxLayout: | |
orientation: 'vertical' | |
Label: | |
text: 'Password' | |
halign: 'left' | |
font_size: 18 | |
text_size: root.width-20, 20 | |
TextInput: | |
id: password | |
multiline:False | |
password:True | |
font_size: 28 | |
Button: | |
text: 'Connexion' | |
font_size: 24 | |
on_press: root.do_login(login.text, password.text) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from kivy.app import App | |
from kivy.properties import StringProperty | |
from kivy.uix.screenmanager import ScreenManager, Screen, SlideTransition | |
import os | |
from connected import Connected | |
class Login(Screen): | |
def do_login(self, loginText, passwordText): | |
app = App.get_running_app() | |
app.username = loginText | |
app.password = passwordText | |
self.manager.transition = SlideTransition(direction="left") | |
self.manager.current = 'connected' | |
app.config.read(app.get_application_config()) | |
app.config.write() | |
def resetForm(self): | |
self.ids['login'].text = "" | |
self.ids['password'].text = "" | |
class LoginApp(App): | |
username = StringProperty(None) | |
password = StringProperty(None) | |
def build(self): | |
manager = ScreenManager() | |
manager.add_widget(Login(name='login')) | |
manager.add_widget(Connected(name='connected')) | |
return manager | |
def get_application_config(self): | |
if(not self.username): | |
return super(LoginApp, self).get_application_config() | |
conf_directory = self.user_data_dir + '/' + self.username | |
if(not os.path.exists(conf_directory)): | |
os.makedirs(conf_directory) | |
return super(LoginApp, self).get_application_config( | |
'%s/config.cfg' % (conf_directory) | |
) | |
if __name__ == '__main__': | |
LoginApp().run() |
Can you explain how the screen management work and transition?
I am getting a complete black screen after running this.
Even I am getting a black screen. Can you let us know how to resolve it?
On windows use python -m conda -c conda-forge kivy wheel pygame cython
Great ... Thanks a lot
Great, super contribution, a question many as I do to take the data of the variable for example, idUser, to the connected file and put print it in that file.
Priyanshthehacker you didnt create that connected.py file wich imports this
awsome dude thnks a lot
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hi,
how to run this code i couldnt understand