Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Cheaterman
Last active March 29, 2024 03:56
Show Gist options
  • Star 25 You must be signed in to star a gist
  • Fork 24 You must be signed in to fork a gist
  • Save Cheaterman/812203a74f8c552a4918 to your computer and use it in GitHub Desktop.
Save Cheaterman/812203a74f8c552a4918 to your computer and use it in GitHub Desktop.
Kivy Login example
<Connected>:
BoxLayout:
orientation: 'vertical'
Label:
text: "You are now connected"
font_size: 32
Button:
text: "Disconnect"
font_size: 24
on_press: root.disconnect()
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()
#: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)
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()
@pipoupiwam
Copy link

Thanks a lot, you're a god :)
micha_

@rtaboadam
Copy link

Dude, thanks a lot

@neuronion
Copy link

So nice example to understand the philosophy of Python and Kivy

@motionfit
Copy link

great, thanks!

@nixen420
Copy link

nixen420 commented Feb 7, 2017

my python version is 2.7.11

@nixen420
Copy link

nixen420 commented Feb 7, 2017

how to run it ...m stuk....i have installed kivy ,wheel,pygame,cython but unable to run it...getting error lyk dis:
error

@nixen420
Copy link

please share what will be the output of dis pgm.

@hbustos
Copy link

hbustos commented Sep 27, 2017

gracias funciona muy bien (thanks, work very well!)

@yiki94
Copy link

yiki94 commented Jan 11, 2018

Hey, very new in python and kivy. Could you tell me how to add actionbar after user log in? Like if user log in it will directed to connected.py, is it possible for actionbar to be inside connected.py? If so, how? Thank you.

@MalokaThato
Copy link

Thanks a lot fairly new to kivy and python and the logic to this has been a killer to get. By going through your code i get why?

Thanks

@marcio-malacarne
Copy link

Hi,
I also had the same error as nixem420.
But I arranged by removing the “:” of the line “#i: nclude connected.kv” of the login.kv file

@MeenaSarvan
Copy link

hi,
how to run this code i couldnt understand

@RanyeM
Copy link

RanyeM commented Jul 19, 2018

Can you explain how the screen management work and transition?

@isrj5
Copy link

isrj5 commented Aug 9, 2018

I am getting a complete black screen after running this.

@vrajesh26
Copy link

Even I am getting a black screen. Can you let us know how to resolve it?

Copy link

ghost commented May 20, 2019

how to run it ...m stuk....i have installed kivy ,wheel,pygame,cython but unable to run it...getting error lyk dis:
error

use this command:
conda install -c conda-forge kivy wheel pygame cython

Copy link

ghost commented May 20, 2019

On windows use python -m conda -c conda-forge kivy wheel pygame cython

@alsakwti
Copy link

Great ... Thanks a lot

@AdSeque
Copy link

AdSeque commented Jul 23, 2021

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
Copy link

Screenshot (2)
there is nothing like connected module...!! please fix this

@stokbrot
Copy link

Priyanshthehacker you didnt create that connected.py file wich imports this

@HARRFRAG
Copy link

awsome dude thnks a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment