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()
@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