Kivy crash course 9: Creating a scrollable label

Alexander Taylor · 46K views · 2014 · 11:50

Open on YouTube

Python, Ruby & scripting languagesSoftware (other)tutorial

Why Stack Overflow recommends it

Stack Overflow users link it when answering Kivy questions about making long labels wrap and scroll inside a ScrollView.

Recommended by 3 people across 3 different months, 2014 to 2015.

What it is

Part 9 of Alexander Taylor's Kivy crash course, building a scrollable label widget from scratch. It shows how a Label manages its text and size, introduces some new widgets, and reuses techniques from earlier episodes.

What people said

Recommends inclement · 2014-07 · Stack Overflow · on “How to properly create long text labels inside ScrollView in Kivy?”

The problem is probably that texture_size isn't updated until the texture is actually generated and displayed, which may not have happened by the end of your method (but probably does before the next frame). For this reason, you generally want to bind to properties, not take their instantaneous values. Your whole rule can be expressed more simply, and with this additional functionality for free, in kv language (I'm making some guesses about the widget addition that you didn't include in the post, but you should see the general idea). : size_hint_y: None height: label2.texture_size[1] Label: # label1 text: 'foo:' Label: # label2 id: label2 text: 'bar' * 50 width: int(Window.width*0.8) # This

Recommends William Barnes · 2015-01 · Stack Overflow · on “Wrapping a listview to the size of window in Kivy”

After messing around quite a lot with the ".kv" file, and the main python program, I came up with a solution, taking a slightly different approach. I dispensed with the listview, and stuck with a simple modal pop-up consisting of a label. I then was able to follow much of the advice in this youtube video [this video] , to make the label wrap and scroll effectively.

Recommends ThePhi · 2015-07 · Stack Overflow · on “Kivy: creating a pan screen effect?”

For a good and quite complete introduction to kivy, the tutorial series done by @inclement are very helpful IMO : [LINK] And you've got in particular a section about scrollable label (or other thing...) : [this video]

Cites DaveQ · 2015-07 · Stack Overflow · on “Python reports invalid syntax when assigning user defined Kivy widget property”

from kivy.uix.label import Label from kivy.uix.scrollview import ScrollView from kivy.uix.boxlayout import BoxLayout from kivy.lang import Builder from kivy.base import runTouchApp from kivy.properties import StringProperty from kivy.properties import ListProperty from kivy.graphics.vertex_instructions import Rectangle from kivy.graphics.context_instructions import Color Builder.load_string(''' <bbx>: orientation: 'vertical' my2App: color: 1,0,0,1 <my2App>: text: root.text Label: text: root.text font_size: 16 size_hint_y: None text_size: self.width, None height: self.texture_size[1] canvas: Color: rgba: root.color Rectangle: pos: self.pos size: self.size ''') class my2App(ScrollView): text =

Cites 0_- · 2015-11 · Stack Overflow · on “Python 3.5 - Kivy Android - ScrollableLabel(ScrollView) - Working on a single line of code for two days”

#!/usr/local/bin/python # -*- coding: utf-8 -*- from kivy.uix.label import Label from kivy.uix.scrollview import ScrollView from kivy.properties import StringProperty from kivy.base import runTouchApp from kivy.lang import Builder import kivy.input.postproc.doubletap import random # Below is the dictionary file, it is over five thousand lines and one million characters, editting it manually may slow the computer down for a moment. d = {'''massive dictionary''': '''in this format''', '''massive dictionary''': '''in this format'''} while True: i = 1 random_list = random.sample(d.items(), i ) print('---------+---------') randomList = random_list # This prints a less aesthetic version compared t