How do I use the text_input python-kivy text?

0

I'm having trouble using text_input text to store in the database.

Python code:

from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.core.window import Window
from kivy.utils import get_color_from_hex

from sqlalchemy import select, MetaData, Table
from sqlalchemy import create_engine


Window.clearcolor = get_color_from_hex("#a52429")
__version__ = "0.1"

engine = create_engine('sqlite:///divinodb.db')
metadata = MetaData()
tab = Table('cadastro', metadata, autoload=True, autoload_with=engine)
tabela = select([tab])
print(tabela)
results = engine.execute(tabela).fetchall()
print(results)


class PaginaInicial(Screen):
        pass

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'

        def switch_page_salvar(self):

                p_nome = str(self.root.ids.name.text)
                p_senha = str(self.root.ids.senhaa.text)
                p_email = str(self.root.ids.email.text)
                p_data = int(self.root.ids.data.text)
                p_endereco = str(self.root.ids.endereco.text)
                p_numero = int(self.root.ids.numero.text)
                p_comp = str(self.root.ids.complemento.text)
                p_refer = str(self.root.ids.refer.text)
                p_dd = int(self.root.ids.dd.text)
                p_telres = int(self.root.ids.telres.text)
                p_ddd = int(self.root.ids.ddd.text)
                p_telcel = int(self.root.ids.telcel.text)

                con = engine.connect()
                ins = tab.insert()

                con.execute(ins, [
                        dict(nome=p_nome, senha=p_senha, email=p_email, data=p_data, endereco=p_endereco,
                             numero=p_numero, complemento=p_comp, refer=p_refer, dd=p_dd, telres=p_telres, ddd=p_ddd, telcel=p_telcel)
                ])
                con.close()
                print(results)
                self.current = 'paginaInicial'

# Database connection

class DivinoSaborApp(App):
        def build(self):
                self.root = ScreenManagement()
                return self.root
if __name__ == '__main__':
        DivinoSaborApp().run()

Kivy Code:

<ScreenManagement>:
    PaginaInicial:
    PageCadastro:
    PageEsqsenha:

 #:import C kivy.utils.get_color_from_hex


<PaginaInicial>:
    name:'paginaInicial'
    FloatLayout:

        Image:
            source:"images/super.jpg"
            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]

        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:
        Label:
            rulesonly:True
            text:"Nome completo: "
            size_hint:(.3,.06)
            pos_hint:{"center_x":.5, "center_y":.95}
            bold:True
            font_size:"15sp"
        Label:
            rulesonly:True
            text:"Senha: "
            size_hint:(.3,.06)
            pos_hint:{"center_x":.5, "center_y":.85}
            bold:True
            font_size:"15sp"
        Label:
            text:"E-mail:"
            size_hint:(None,None)
            pos_hint:{"center_x":.5, "center_y":.75}
            bold:True
            font_size:"15sp" 
        Label:
            text:"Data de Nascimento:"
            size_hint:(None,None)
            pos_hint:{"center_x":.5, "center_y":.65}
            bold:True
            font_size:"15sp" 
        Label:
            text:"Endereco: "
            rulesonly:True
            size_hint:(None,None)
            pos_hint:{"center_x":.5, "center_y":.55}
            bold:True
            font_size:"15sp" 
        Label:
            text:"Numero: "
            size_hint:(None,None)
            pos_hint:{"center_x":.38, "center_y":.45}
            bold:True
            font_size:"15sp"
        Label:
            text:"Complemento: "
            size_hint:(None,None)
            pos_hint:{"center_x":.61, "center_y":.45}
            bold:True
            font_size:"13sp"
        Label:
            text:"Referencia: "
            size_hint:(None,None)
            pos_hint:{"center_x":.5, "center_y":.35}
            bold:True
            font_size:"15sp"
        Label:
            text:"Telefone residencial: "
            size_hint:(None,None)
            pos_hint:{"center_x":.5, "center_y":.25}
            bold:True
            font_size:"15sp"
        Label:
            text:"Celular/WhatsApp: "
            size_hint:(None,None)
            pos_hint:{"center_x":.5, "center_y":.15}
            bold:True
            font_size:"15sp"

        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_page_salvar()
            background_color:(235,36,31,0)
            text: 'Avançar'
        TextInput:
            id: name
            pos_hint:{"center_x":.5, "center_y":.9}
            size_hint:(.4,.05)
            multiline:False
            write_tab: False
        TextInput:
            id: senhaa
            pos_hint:{"center_x":.5, "center_y":.8}
            size_hint:(.4,.05)
            multiline:False
            write_tab: False
            password: True
        TextInput:
            id: email
            pos_hint:{"center_x":.5, "center_y":.7}
            size_hint:(.4,.05)
            multiline:False
            write_tab: False
        TextInput:
            id: data
            pos_hint:{"center_x":.5, "center_y":.6}
            size_hint:(.4,.05)
            multiline:False
            write_tab: False
        TextInput:
            id: endereco
            pos_hint:{"center_x":.5, "center_y":.5}
            size_hint:(.4,.05)
            multiline:False
            write_tab: False
        TextInput:
            id: numero
            pos_hint:{"center_x":.37, "center_y":.4}
            size_hint:(.14,.05)
            multiline:False
            write_tab: False
            input_filter:'int'
        TextInput:
            id: complemento
            pos_hint:{"center_x":.6, "center_y":.4}
            size_hint:(.2,.05)
            multiline:False
            write_tab: False
            input_filter:'int'
        TextInput:
            id: refer
            pos_hint:{"center_x":.5, "center_y":.3}
            size_hint:(.4,.05)
            multiline:False
            write_tab: False
        TextInput:
            id: dd
            pos_hint:{"center_x":.35, "center_y":.2}
            size_hint:(.1,.05)
            multiline:False
            write_tab: False
            input_filter:'int'
        TextInput:
            id: telres
            pos_hint:{"center_x":.57, "center_y":.2}
            size_hint:(.26,.05)
            multiline:False
            write_tab: False
            input_filter:'int'
        TextInput:
            id: ddd
            pos_hint:{"center_x":.35, "center_y":.1}
            size_hint:(.1,.05)
            multiline:False
            write_tab: False
            input_filter:'int'
        TextInput:
            id: telcel
            pos_hint:{"center_x":.57, "center_y":.1}
            size_hint:(.26,.05)
            multiline:False
            write_tab: False
            input_filter:'int'

<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'
    
asked by anonymous 16.11.2018 / 18:16

1 answer

0

According to the manual , here is an example of use:

from kivy.uix.textinput import TextInput
textinput = TextInput(text='Hello world')

Another example:

def messageShow(self,evt):
    if self.txt1.text == "stock":
        pop=Popup(text="yes")
    else:
        pop=Popup(text="error")

Remember, since you're doing SQL, do not forget the double quotation marks in string. Ex:

'SELECT * FROM tabela WHERE campo = "suaString" ';
    
16.11.2018 / 18:25