I have a TextInput
that is added to a kivy language <MyLayout>:
rule and declared as a python class that inherits from a BoxLayout
. The above rule is then added to a ModalView
along with some buttons when another button is clicked. The main problem is that although I can get an instance of the text of the buttons within the <MyLayout>:
rule and pass the text to the TextInput
, I cannot seem to get the TextInput
text output via a function called process_output()
.
The only reason I can guess is because the TextInput
gets garbage collected. There is no error and the console prints carriage return as the output is empty but the screen moves up when I try to print()
the TextInput
text.
Python code:
class RootLay(FloatLayout):
def get_keys(self):
modal = ModalViewer()
the_key = MyLayout()
modal.add_widget(the_key)
modal.open()
def process_output(self):
mod = ModalViewer()
the_key = MyLayout()
the_output = the_key.ids.show_input.text
the_key.ids.show_input.text = ''
print(the_output)
mod.dismiss()
class MyLayout(BoxLayout):
show_input = ObjectProperty()
def __init__(self, **kwargs):
super(MyLayout, self).__init__(**kwargs)
btn = ['7', '8', '9', '4', '5', '6', '1', '2', '3', 'IN', '0', 'OUT']
key_padbtns = []
for b in btn:
key_padbtns.append({'text': b, 'size_hint': [1, 1]})
self.ids.view_keypad.data = key_padbtns
Kivy code:
<RootLay>:
Button:
text: 'Press for key'
on_release: app.root.get_keys()
<MyLayout>:
id: emp_keys
orientation: 'vertical'
size_hint: (0.94, 0.94)
pos_hint: {'top': 0.94}
TextInput:
id: show_input
hint_text: 'Type number'
font_size: self.height / 1.7
size_hint_y: 0.1
RecycleView:
id: view_keypad
viewclass: 'KeyBut'
size_hint: [1,1]
RecycleGridLayout:
cols: 3
defualt_size: [100, 20]
defualt_size_hint: [1,1]
<KeyBut>:
on_press:
if self.text == 'OUT' or self.text == 'IN': app.root.process_output()
else: self.parent.parent.parent.ids.show_input.text = self.parent.parent.parent.ids.show_input.text + self.text
Can someone please give me idea of what is going wrong?