Answer the question
In order to leave comments, you need to log in
How to get value of text input kivy?
I have already used text input, but this time I am forced to look for a solution here. I tried using id: ... but
no luck
:
size_hint_y: 0.2
text: 'get links'
on_press:
self.FROM = 'lon' # this works
self.TO = 'par' # this works
#self.FROM = from_ .text ############ cannot get this value
#app.TO = to_.text ####
#self.links_grid.clear_widgets()
#self.clear_widgets()
self.SEARCH()
Here is the code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from kivy.app import App
from kivy.uix.button import Button
from kivy.lang import Builder
class GetLinksButton(Button):
def __init__(self, **kwargs):
super(GetLinksButton, self).__init__(**kwargs)
self.FROM = ''
self.TO = ''
t = '''
'Driver Pego', 'London - Paris'
'Driver Pego', 'London - Sidney'
'Driver Pego', 'London - Rom'
'Driver Pego', 'Vena - Paris'
'Driver Pego', 'Goa - Paris'
'''
self.DRIVES = t.read().split("\n")
link_number = 1
def get_links(self):
self.links_grid.clear_widgets(self.children)
self.link_number = 1
for i in self.DRIVES:
print(i)
try:
i = ','.join(i)
except:
pass
link_button = LinkButton(
text=str(self.link_number) + ' / ' +
" / ".join(i.split(","))
)
self.link_number += 1
self.links_grid.add_widget(link_button)
def SEARCH(self):
D = self.DRIVES
d = []
print('==============\n',self.FROM.lower())
if self.FROM != '' and self.FROM != 'From':
for i in list(set(D)):
if i!='':
place = list(eval(i))[1].split('-')[0].lower().strip()
if place.startswith(self.FROM.lower().strip()):
d.append(list(eval(i)))
D = d
d = []
if self.TO != '' and self.TO != 'To':
for i in D:
if i!='':
place2 = i[1].split('-')[1].lower()
if self.TO.lower() in place2:
d.append(i)
D = d
d = []
self.DRIVES = D
self.get_links()
class LinkButton(Button):
pass
class Test(App):
def build(self):
return root
root = Builder.load_string('''
#:kivy 1.9.0
#:set color_button (227/255., 62/255., 26/255.,.8)
#:set Font2 35
#:set Font 40
GridLayout:
#rows: 1
cols: 1
padding: 5
spacing: 10
from_: from_
to_: to_
TI:
text: "From"
id: from_
TI:
text: "To"
id: to_
RightArea:
:
background_color: color_button
background_normal: ''
pos_hint: {'center_x': .5, 'center_y':.5}
size_hint: .3, .2
never_selected: False
text:' Input amount '
#input_filter: 'int'
padding_y: [self.height / 2.0 - (self.line_height / 2.0) * len(self._lines), 0]
padding_x: [self.width / 2.0 - self._get_text_width(max(self._lines, key=len), self.tab_width, self._label_cached) / 2.0, 0] if self.text else [self.center[0], 0]
on_focus: if self.never_selected == False: self.text = ''; self.never_selected = True
font_size: 30
multiline:False
halign: 'right'
valign: 'middle'
font_size: Font
font_color: 1,1,1,1
foreground_color: color_font
foreground_color: 1,1,1,1
#on_release: app.SUMM = self.text
:
cols: 1
size_hint_x: 0.3
spacing: '10dp'
ScrollView:
LinksGrid:
id: links_grid
background_color: color_button
background_normal: ''
font_size: Font
GetLinksButton:
links_grid: links_grid
background_color: color_button
text: "SEARCH"
background_normal: ''
font_size: Font
:
cols: 1
spacing: '5dp'
size_hint_y: None
height: self.minimum_height
:
size_hint_y: 0.2
text: 'get links'
on_press:
self.FROM = 'lon'
self.TO = 'par'
#from_.text
#app.TO = to_.text
#self.links_grid.clear_widgets()
#self.clear_widgets()
self.SEARCH()
:
size_hint_y: None
height: '80dp'
font_size: 30
background_color: color_button
background_normal: ''
''')
Test().run()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question