0

I have this scrollable label but when the text is too long, it's displayed as a black rectangle (cf the print screen at the top). If I remove about half of the text in the label, then it's displayed as expected (cf the print screen at the bottom) enter image description here Any idea how to fix this?

import kivy
from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.uix.button import Button
from kivy.uix.popup import Popup
from kivy.uix.label import Label
from kivy.uix.scrollview import ScrollView
from kivy.core.window import Window

class Test(App):
    def build(self):
        Window.clearcolor = (0.863, 0.863, 0.863, 0.9)
        layout_pop  = GridLayout (cols=3)
        for i in range(1):
            l = Label(text="1abcdefghijklmnopqrstuvwxyz_2abcdefghijklmnopqrstuvwxyz_3abcdefghijklmnopqrstuvwxyz_4abcdefghijklmnopqrstuvwxyz_5abcdefghijklmnopqrstuvwxyz_6abcdefghijklmnopqrstuvwxyz_7abcdefghijklmnopqrstuvwxyz_8abcdefghijklmnopqrstuvwxyz 1abcdefghijklmnopqrstuvwxyz_2abcdefghijklmnopqrstuvwxyz_3abcdefghijklmnopqrstuvwxyz_4abcdefghijklmnopqrstuvwxyz_5abcdefghijklmnopqrstuvwxyz_6abcdefghijklmnopqrstuvwxyz_7abcdefghijklmnopqrstuvwxyz_8abcdefghijklmnopqrstuvwxyz1abcdefghijklmnopqrstuvwxyz_2abcdefghijklmnopqrstuvwxyz_3abcdefghijklmnopqrstuvwxyz_4abcdefghijklmnopqrstuvwxyz_5abcdefghijklmnopqrstuvwxyz_6abcdefghijklmnopqrstuvwxyz_7abcdefghijklmnopqrstuvwxyz_8abcdefghijklmnopqrstuvwxyz 1abcdefghijklmnopqrstuvwxyz_2abcdefghijklmnopqrstuvwxyz_3abcdefghijklmnopqrstuvwxyz_4abcdefghijklmnopqrstuvwxyz_5abcdefghijklmnopqrstuvwxyz_6abcdefghijklmnopqrstuvwxyz_7abcdefghijklmnopqrstuvwxyz_8abcdefghijklmnopqrstuvwxyz1abcdefghijklmnopqrstuvwxyz_2abcdefghijklmnopqrstuvwxyz_3abcdefghijklmnopqrstuvwxyz_4abcdefghijklmnopqrstuvwxyz_5abcdefghijklmnopqrstuvwxyz_6abcdefghijklmnopqrstuvwxyz_7abcdefghijklmnopqrstuvwxyz_8abcdefghijklmnopqrstuvwxyz 1abcdefghijklmnopqrstuvwxyz_2abcdefghijklmnopqrstuvwxyz_3abcdefghijklmnopqrstuvwxyz_4abcdefghijklmnopqrstuvwxyz_5abcdefghijklmnopqrstuvwxyz_6abcdefghijklmnopqrstuvwxyz_7abcdefghijklmnopqrstuvwxyz_8abcdefghijklmnopqrstuvwxyz",
                      font_size=15, 
                      color=(1,1,3,1), 
                      size_hint_x= None)  
            l.bind(texture_size=l.setter('size'))
            l.bind(size_hint_min_x=l.setter('width'))
            scroll = ScrollView(size_hint=(None, None), size=(800, 30))
            scroll.add_widget(l)
            layout_pop.add_widget(scroll)
        return layout_pop

Test().run()
MagTun
  • 5,619
  • 5
  • 63
  • 104
  • A similar issue has been addressed [here](http://stackoverflow.com/questions/37090869/kivy-black-screen-error-in-label) – ODiogoSilva Mar 08 '17 at 19:03
  • @ODiogoSilva. Thanks for this. There are two issues: first I can't use kv language, so is it possible to adapt ScrollLabel to be in python only. Second, I can't find how to install the garden depencies. I tried garden install scrolllabel in cmd but I get this error "python.exe: can't open file 'C:\Users\xx': [Errno 2] No such file or directory (My Windows 7 username is "xx xx"). In python console I get SyntaxError: invalid syntax. I tried to find the follow the advices here http://stackoverflow.com/questions/26172541/kivy-garden-fails-with-error but without succes. Kivy Garden is installed. – MagTun Mar 09 '17 at 19:14

1 Answers1

0

No an actual solution, but there are two workaround I ended up using:

● only displaying the 100 first characters

if len(text)>100:
    text= text[0:100]+" (...)"

● inserting a \n at each position multiple of 100

MagTun
  • 5,619
  • 5
  • 63
  • 104