Python:
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen
from sqlalchemy import MetaData, Table
from sqlalchemy import create_engine
from sqlalchemy import String
DATABASE = 'sqlite:///divinodb.db'
metadata = MetaData()
engine = create_engine(DATABASE)
cadastro = Table('cadastro', metadata, autoload=True, autoload_with=engine)
class PaginaInicial(Screen):
def gravar(self):
nome = self.root.ids.usuario.textinput
if nome == type(String):
nome.execute('INSERT nome FROM cadastro')
results = cadastro.execute(nome).fetchall()
print(results)
return results
class PageEsqsenha(Screen):
pass
class PageCadastro(Screen):
pass
class ScreenManagement(ScreenManager):
def switch_to_pageCadastro(self):
self.current = 'pageCadastro'
def switch_to_paginaInicial(self):
self.current = 'paginaInicial'
def switch_to_pageEsqsenha(self):
self.current = 'pageEsqsenha'
# Database connection
class TesteDbApp(App):
def build(self):
self.root = ScreenManagement()
return self.root
if __name__ == '__main__':
TesteDbApp().run()
kivy:
<ScreenManagement>:
PaginaInicial:
PageCadastro:
PageEsqsenha:
<PaginaInicial>:
name:'paginaInicial'
FloatLayout:
Image:
source:"images/super.png"
size_hint:(1, .3)
pos_hint:{"center_x":.5, "center_y":.65}
Image:
source:"images/Logo.jpg"
size_hint:(.8, .6)
pos_hint:{"center_x":.5,"center_y":.9}
Label:
text:"Usuario: "
size_hint:(None,None)
pos_hint:{"center_x":.37, "center_y":.43}
bold:True
font_size:"15sp"
Label:
text:"Senha: "
size_hint:(None,None)
pos_hint:{"center_x":.37,"center_y":.36}
bold:True
font_size:"15sp"
TextInput:
id: usuario
pos_hint:{"center_x":.59, "center_y":.43}
size_hint:(.25,.05)
multiline:False
write_tab: False
TextInput:
id: senha
pos_hint:{"center_x":.59, "center_y":.36}
size_hint:(.25,.05)
multiline:False
write_tab:False
password:True
Button:
text:"Entrar"
pos_hint:{"center_x":.5,"center_y":.28}
size_hint:(.3,.05)
background_down:''
background_color:[16,16,16,0.1]
on_press:root.gravar()
Button:
text:"Esqueceu sua senha?"
size_hint:(.25,.03)
pos_hint:{"center_x":.5,"center_y":.2}
bold:True
font_size:"8sp"
on_release:app.root.switch_to_pageEsqsenha()
background_color:[1,1,1,0]
Button:
text:"Cadastre-se!"
size_hint:(.15,.03)
pos_hint:{"center_x":.5,"center_y":.15}
bold:True
font_size:"8sp"
on_release:app.root.switch_to_pageCadastro()
background_color:[1,1,1,0]
<PageCadastro>:
name: 'pageCadastro'
FloatLayout:
Button:
size_hint:.2,.06
pos_hint:{'left':1, 'center_y':.03}
on_release: app.root.switch_to_paginaInicial()
background_color:(235,36,31,0)
text: 'Voltar'
Button:
size_hint:.2,.06
pos_hint:{'right':1,'center_y':.03}
on_release: app.root.switch_to_paginaInicial()
background_color:(235,36,31,0)
text: 'Avançar'
<PageEsqsenha>:
name: 'pageEsqsenha'
FloatLayout:
Button:
size_hint:.2,.06
pos_hint:{'left':1, 'center_y':.03}
on_release: app.root.switch_to_paginaInicial()
background_color:(235,36,31,0)
text: 'Voltar'