I am writing an app in Python (3.9-64) using Kivy (2.2.1) framework. I have a Label in ScrollView that has many lines. The scrolling works ok as long as the text is not too large in terms of the space it occupies on the screen, i.e. if I reduce font size, I can view text with more lines. If the text is too long at a give font size, no text is displayed.
Bellow is the MWE. When I was testing on my Windows machine (the behavior does not change if I change the display resolution) the text (1000 lines, but it can be set to more or less by changing the value of the m
variable in the code) is displayed if font size 11 or less (self.fontSizeSmall
in the code) and not if it is 12 or lager.
The behavior is the same (although I do not know exact length of text and font size) on my android app on a Samsung phone when build on Ubuntu using buildozer.
Any help would be much appreciated. I have found several similar questions on StackOverflow, however most were not using a single Label and I must admit I have not understood well the solutions.
Here is the code:
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.uix.scrollview import ScrollView
from kivy.core.window import Window
m = 200
class MainApp(App):
def build(self):
self.fontSize=24
self.fontSizeSmall=12
self.widgetsFontSize=[]
self.widgetsFontSizeSmall=[]
main_layout = BoxLayout(orientation="vertical")
self.zgodovina=""
for i in range(m):
self.zgodovina= """
Some multilne, but not too long text.
Repeated multplie times.
In acctual app these are log entires.
There can be really a lot of them
""" + self.zgodovina
scrollViewHist=ScrollView(size_hint=(None,5), size=(Window.width, Window.height))
self.ZgodovinaLabel=Label(text=self.zgodovina,size_hint=(None, None), padding=[10,0], font_size=self.fontSizeSmall)
self.ZgodovinaLabel.bind(texture_size=self.ZgodovinaLabel.setter('size'))
self.ZgodovinaLabel.bind(size_hint_min_x=self.ZgodovinaLabel.setter('width'))
scrollViewHist.add_widget(self.ZgodovinaLabel)
self.widgetsFontSizeSmall.append(self.ZgodovinaLabel)
main_layout.add_widget(scrollViewHist)
fontPlusButton=Button(text="Font +", font_size=self.fontSize)
fontPlusButton.bind(on_press=self.fontPlus)
main_layout.add_widget(fontPlusButton)
self.widgetsFontSize.append(fontPlusButton)
fontMinusButton=Button(text="Font -", font_size=self.fontSize)
fontMinusButton.bind(on_press=self.fontMinus)
main_layout.add_widget(fontMinusButton)
self.widgetsFontSize.append(fontMinusButton)
return main_layout
def fontPlus(self, instance):
self.fontSize=self.fontSize+2
self.fontSizeSmall=self.fontSizeSmall+1
print(self.fontSizeSmall)
for iWidget in self.widgetsFontSize:
iWidget.font_size=self.fontSize
for iWidget in self.widgetsFontSizeSmall:
iWidget.font_size=self.fontSizeSmall
def fontMinus(self, instance):
self.fontSize=self.fontSize-2
self.fontSizeSmall=self.fontSizeSmall-1
print(self.fontSizeSmall)
for iWidget in self.widgetsFontSize:
iWidget.font_size=self.fontSize
for iWidget in self.widgetsFontSizeSmall:
iWidget.font_size=self.fontSizeSmall
MainApp().run()
You are exceeding the maximum supported texture size in your Label
. You can access that maximum using:
from kivy.graphics.opengl import glGetIntegerv, GL_MAX_TEXTURE_SIZE
print('max texture size:', glGetIntegerv(GL_MAX_TEXTURE_SIZE)[0])
Any texture with either dimension greater than the GL_MAX_TEXTURE_SIZE
will be silently ignored. Perhaps using a BoxLayout
with the text spread among multiple Labels
would work.