Skip to content

Instantly share code, notes, and snippets.

@el3
Last active April 5, 2023 11:05
Show Gist options
  • Save el3/44d963a8971ead9d3f6a741e7134e547 to your computer and use it in GitHub Desktop.
Save el3/44d963a8971ead9d3f6a741e7134e547 to your computer and use it in GitHub Desktop.
Long text split by "\n" put into labels in recycleview
from kivy.app import App
from kivy.properties import ListProperty
from kivy.lang import Builder
long_text = 'This is an example to output a very long file as labels in a recycleboxlayout with line numbers and proper line breakings\n' * 1000 + " END"
KV = '''
<MyLabel@Label>:
halign: "left"
text_size: self.width, None
height: self.texture_size[1]+8
# plus 8 to ad some spacing between the next line
markup: True
RecycleView:
viewclass: 'MyLabel'
data: app.data
RecycleBoxLayout:
id: layout
default_size: None, None
default_size_hint: 1, None
size_hint_y: None
height: self.minimum_height
orientation: 'vertical'
'''
class ScrollApp(App):
data = ListProperty([{"text": "{}".format(line)} for line in long_text.split("\n")])
def build(self):
return Builder.load_string(KV)
if __name__ == "__main__":
ScrollApp().run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment