Send vars from Some TextInput in the Screen (.kv) in file.py by press Button

13 views
Skip to first unread message

alexzinc...@gmail.com

unread,
May 18, 2018, 1:33:47 PM5/18/18
to Kivy users support
Hello!!!
Sorry for the clumsy English))
I'm interested in this question
As it is possible from several TEXTINPUT in screen in kv files to transfer values ​​of variables in a file .py. All my attempts were unsuccessful ((
Here is the code snippet


------------------------------------1 .kv ----------------------------------------------
ShowcaseScreen:
    name: 'Client' 
    fullscreen: True      

    Screen:
        BoxLayout:
            orientation: 'vertical'
            size_hint: .9,.85
            spacing: 10  


            TextInput: 
                background_color: 0,0,0,.2
                background_normal: 'email_icon.png' 
                never_selected: False   
                text:'Email'           
                padding_y: [self.height / 2.0 - (self.line_height / 2.0) * len(self._lines), 0]      
                on_focus: if self.never_selected == False: self.text = ''; self.never_selected = True
                id: psw
                multiline:False
                font_size: Font  

            Button:            
                background_color: color_button
                background_normal: ''   
                size_hint: 1,1.2
                pos_hint: {'center_x': .5, 'center_y': .5}             
                text: ''
                color: color_font
                font_size: Font
                # on_release:
                #     app.sms.open()

            TextInput: 
                background_color: 0,0,0,.2
                background_normal: '' 
                never_selected: False   
                text:'Code'           
                padding_y: [self.height / 2.0 - (self.line_height / 2.0) * len(self._lines), 0]      
                on_focus: if self.never_selected == False: self.text = ''; self.never_selected = True
                id: psw
                multiline:False
                font_size: Font 
            
            Label:            
                text_size: self.size
                background_color: 0,0,0,.5
                background_normal: ''
                halign: 'justify'
                valign: 'middle'
                color: 0, 0, 0, .5
                text: """ somethihg """
                font_size: Font   

            # <ScrollableLabel>: #
            Label:
                size_hint_y: None
                background_color: 1,1,1,.5
                background_normal: ''
                height: self.texture_size[1]
                #text: long_text
                #text_size: 
                color: color_button
                #text: app.root.text  
                    
            Button:            
                background_color: color_button
                background_normal: ''                
                #size_hint: .4,.006 
                size_hint: 1,1.2
                pos_hint: {'center_x': .5, 'center_y': .5}             
                text: 'CONTINUE'
                color: color_font
                font_size: Font
                on_release: app.root.current =  app.go_screen(app.screen_names.index('Autorize')) 

---------------------------------------------2 kv ---------------------------------------------------

ShowcaseScreen:
    name: 'Register'
    fullscreen: True  
        
    Screen:
        BoxLayout:
            orientation: 'vertical'
            size_hint: .9,.85
            spacing: 10
            pos_hint: {'center_x': .5, 'center_y': .5}
            background_normal: ''
            background_color: 1,1,1,0

        Button:            
                background_color: color_button
                background_normal: '' 
                background_down: ''                    
                
                pos_hint: {'center_x': .5, 'center_y': .5}             
                text: 'Registration'
                color: color_font
                font_size: Font
                on_release: app.go_screen(app.screen_names.index('Client'))
            

            TextInput: 
                id: log
                background_color: color_button
                background_normal: ''  
                never_selected: False 
                
                pos_hint: {'center_x': .5, 'center_y': .5} 
                text:'Login'           
                padding_y: [self.height / 2.0 - (self.line_height / 2.0) * len(self._lines), 0]      
                on_focus: if self.never_selected == False: self.text = ''; self.never_selected = True
                id: login
                multiline:False            
                font_size: Font 
                color: 1,1,1,1
                #on_release: LOGIN = self.text;

            
            TextInput:
                id: psw 
                background_color: color_button
                background_normal: '' 
                never_selected: False                
                pos_hint: {'center_x': .5, 'center_y': .5} 
                text:'Password'           
                padding_y: [self.height / 2.0 - (self.line_height / 2.0) * len(self._lines), 0]      
                on_focus: if self.never_selected == False: self.text = ''; self.never_selected = True
                id: psw
                multiline:False
                font_size: Font                
                password: True
                color: 1,1,1,1
                #on_release: PASSWORD = self.text
                
                
           

            Button:  
                background_color: color_button
                background_normal: ''  
                
                pos_hint: {'center_x': .5, 'center_y': .5}             
                text: 'Login'
                color: color_font
                font_size: Font
                #height: '48dp'
                on_release:   
                    print(self.ids.log.text)                    
                    print(self.ids.psw.text)                                 
                    app.check_log(self.ids.log.text, self.ids.psw.text)
                    # self.ids.log.text, self.ids.psw.text
--------------------------------------------------------------------------------------------
part of file.py   (if it need ...)


import login 
from time import time
from kivy.app import App
from os.path import dirname, join
from kivy.lang import Builder
from kivy.properties import NumericProperty, StringProperty, BooleanProperty,\
    ListProperty, ObjectProperty
from kivy.clock import Clock
from kivy.animation import Animation
from kivy.uix.screenmanager import Screen
#from kivy.core.clipboard import Clipboard
import datetime




class ShowcaseScreen(Screen):
    fullscreen = BooleanProperty(False)

    def add_widget(self, *args):
        if 'content' in self.ids:
            return self.ids.content.add_widget(*args)
        return super(ShowcaseScreen, self).add_widget(*args)

class Acount(ShowcaseScreen): pass


class ShowcaseApp(App):


    index = NumericProperty(-1)
    current_title = StringProperty()
    time = NumericProperty(0)
    show_sourcecode = BooleanProperty(False)
    sourcecode = StringProperty()
    screen_names = ListProperty([])
    hierarchy = ListProperty([])



    def build(self):

        self.cur = StringProperty()
        self.method = StringProperty()
        self.LOGIN = ''
        self.PASSWORD = StringProperty()
        self.number = NumericProperty(0)
        self.log    = ObjectProperty()
        self.psw    = ObjectProperty()

        self.company= ObjectProperty()
        self.model  = ObjectProperty()
        self.number = ObjectProperty()
        self.seats  = ObjectProperty()
        

ZenCODE

unread,
May 20, 2018, 9:15:51 AM5/20/18
to Kivy users support
That is a lot to work through. Can you not prepare a minimal, runnable example showing what you would like to do? You can used kivy.properties to easily transfer values between kv and python.

Reply all
Reply to author
Forward
0 new messages