Here, I am having a MDTextfield that should take values as I type on the characters on the keyboard. But for some reason, the characters are clickable and respond, but they do not get written into the MDTextfield. SO I tried with creating function called write_text() (just in case of the letter "a") and then do its implementation in the Python file. But this requires me to address the id of that MDTextField in my python file. That is where the problem is.
Here is my kivy code (the part we are interested in is , at the bottom)
#:import MyLayout main2.MyLayout
MyLayout:
MDLabel:
id: task_label
halign: "center"
markup: True
text:"[b][u][size=48]Your Task Manager[/size][/u][/b]"
pos_hint: {"y": 0.45}
ScrollView:
pos_hint: {"center_y": 0.5, "center_x": 0.5}
size_hint: 0.9, 0.8
MDList:
id: container
OneLineListItem:
text: "Clickable Area for adding task"
on_release: app.clickable_item()
MDFloatingActionButton:
icon: "plus-thick"
on_release: app.task_dialog()
elevation_normal: 12
pos_hint: {"x": 0.45 , "y": 0.04}
<TaskDialogContent>:
orientation: "vertical"
spacing: "10dp"
size_hint : 1, None
height: "130dp"
GridLayout:
rows: 1
MDTextField:
id: task_text
hint_text: "Add a task ..."
pos_hint: {"center_y": 0.4}
max_text_length: 50
on_text_validate: (app.add_task(task_text.text), app.close_task_dialog())
BoxLayout:
orientation: "horizontal"
MDRaisedButton:
text: "SAVE"
on_release: (app.add_task(task_text.text), app.close_task_dialog())
MDFlatButton:
text: "CANCEL"
on_release: app.close_task_dialog()
<SubTaskDialogContent>:
id: subtask_content
orientation: "vertical"
spacing: "10dp"
size_hint : 1, None
height: "130dp"
GridLayout:
rows: 1
MDTextField:
id: subtask_text
hint_text: "Add a subtask ..."
pos_hint: {"center_y": 0.4}
max_text_length: 50
on_text_validate: app.add_subtask(subtask_content.ids.subtask_text.text), app.close_subtask_dialog()
BoxLayout:
orientation: "horizontal"
MDRaisedButton:
text: "SAVE"
on_release: app.add_subtask(subtask_content.ids.subtask_text.text), app.close_subtask_dialog()
MDFlatButton:
text: "CANCEL"
on_release: app.close_subtask_dialog()
<SubTaskShowContent>:
orientation: "vertical"
ScrollView:
GridLayout:
id: subtasks_grid
cols: 1
spacing: dp(5)
<KeyboardContent>:
BoxLayout:
orientation: "vertical"
MDTextField:
id: text_input
hint_text: "Type here"
GridLayout:
cols: 6
spacing: "10dp"
MDRectangleFlatButton:
text: "A"
on_release:
app.write_text(text_input.text)
app.speak_text("a")
MDRectangleFlatButton:
text: "B"
on_release:
text_input.text += self.text
app.speak_text("b")
MDRectangleFlatButton:
text: "C"
on_release:
text_input.text += self.text
app.speak_text("c")
MDRectangleFlatButton:
text: "D"
on_release:
text_input.text += self.text
app.speak_text("d")
MDRectangleFlatButton:
text: "E"
on_release:
text_input.text += self.text
app.speak_text("e")
MDRectangleFlatButton:
text: "F"
on_release:
text_input.text += self.text
app.speak_text("f")
MDRectangleFlatButton:
text: "G"
on_release:
text_input.text += self.text
app.speak_text("g")
MDRectangleFlatButton:
text: "H"
on_release:
text_input.text += self.text
app.speak_text("h")
MDRectangleFlatButton:
text: "I"
on_release:
text_input.text += self.text
app.speak_text("i")
MDRectangleFlatButton:
text: "J"
on_release:
text_input.text += self.text
app.speak_text("j")
MDRectangleFlatButton:
text: "K"
on_release:
text_input.text += self.text
app.speak_text("k")
MDRectangleFlatButton:
text: "L"
on_release:
text_input.text += self.text
app.speak_text("l")
MDRectangleFlatButton:
text: "M"
on_release:
text_input.text += self.text
app.speak_text("m")
MDRectangleFlatButton:
text: "N"
on_release:
text_input.text += self.text
app.speak_text("n")
MDRectangleFlatButton:
text: "O"
on_release:
text_input.text += self.text
app.speak_text("o")
MDRectangleFlatButton:
text: "P"
on_release:
text_input.text += self.text
app.speak_text("p")
MDRectangleFlatButton:
text: "Q"
on_release:
text_input.text += self.text
app.speak_text("q")
MDRectangleFlatButton:
text: "R"
on_release:
text_input.text += self.text
app.speak_text("r")
MDRectangleFlatButton:
text: "S"
on_release:
text_input.text += self.text
app.speak_text("s")
MDRectangleFlatButton:
text: "T"
on_release:
text_input.text += self.text
app.speak_text("t")
MDRectangleFlatButton:
text: "U"
on_release:
text_input.text += self.text
app.speak_text("u")
MDRectangleFlatButton:
text: "V"
on_release:
text_input.text += self.text
app.speak_text("v")
MDRectangleFlatButton:
text: "W"
on_release:
text_input.text += self.text
app.speak_text("w")
MDRectangleFlatButton:
text: "X"
on_release:
text_input.text += self.text
app.speak_text("x")
MDRectangleFlatButton:
text: "Y"
on_release:
text_input.text += self.text
app.speak_text("y")
MDRectangleFlatButton:
text: "Z"
on_release:
text_input.text += self.text
app.speak_text("z")
MDRectangleFlatButton:
text: "Space"
on_release:
text_input.text += " "
app.speak_text("space")
MDRectangleFlatIconButton:
text: "Delete"
icon: "backspace-outline"
on_release:
app.speak_text("delete")
text_input.text = text_input.text[:-1]
MDRectangleFlatIconButton:
text: "Done"
icon: "check-all"
on_release:
app.add_task(text_input.text)
app.close_keyboard_dialog()
app.speak_text("Done. Task Added successfully.")
And here is the implementation of write_text() in the python file.
def write_text(self, sometext):
text_input = self.root.ids.keyboard_content.ids.text_input
text_input.text += sometext