Reputation: 355
The question is as the title reads, I am trying to implement a feature that allows the user of my app to edit the contents of the editable text field (there will be some pre-written stuff, but I want to allow the user to edit it).
Upvotes: 0
Views: 609
Reputation: 1446
Sure, there are a few in-built widgets that could help you out. The first is ScrollView (https://kivy.org/doc/stable/api-kivy.uix.scrollview.html) the second is TextInput (https://kivy.org/doc/stable/api-kivy.uix.textinput.html).
I think you could combine these two to achieve something like what you've suggested.
Try adding this to you're kv file:
ScrollView:
id: scroll_view
TextInput:
text: 'Some random text'
size_hint: 1, None
height: max(self.minimum_height, scroll_view.height)
Just remember that ScrollView will only scroll if there is something to scroll. To scroll vertically, You should set the width of the TextInput to the width of it's parent ScrollView and the height should be set to whichever is greater, the height of the ScrollView or the height of the TextInput.
For completeness, here is some sample code that creates a scrollable text field:
from kivy.app import App
from kivy.lang import Builder
kv = Builder.load_string(
"""
ScrollView:
id: scroll_view
TextInput:
text: 'Some random text'
size_hint: 1, None
height: max(self.minimum_height, scroll_view.height)
"""
)
class ScrollableTextApp(App):
def build(self):
return kv
if __name__ == '__main__':
ScrollableTextApp().run()
Upvotes: 1