'Kivy Scrollview - how to reset scrollbar size?
Noob here. I'm sure there is a simple solution to this but after hours of researching I can't seem to find the answer. I have a program that accepts input and returns the results to a Label in Kivy. The Label is a child of Scrollview. The problem I'm having is that when new input is entered the results are sent back to the Label to replace the previous results BUT the previous scrollbar doesn't reset to fit the size of the new returned results. So if the initial results are 10 lines long and the 2nd set of results are 100 lines long, the scollview only shows the first 10 results. Conversely if the 1st result is 100 lines long and the 2nd result is 10 lines long the 2nd results get placed in a container with a very long scrollbar and lots of empty space. Not ideal. Here's a sample of code that reproduces the issue I'm having.
Py Code:
from kivymd.app import MDApp
from kivy.lang import Builder
class MainApp(MDApp):
def build(self):
return Builder.load_file('testscroll.kv')
def press_btn(self):
self.root.ids.lbl1.text = "Hello There" * 500
def press_btn2(self):
self.root.ids.lbl1.text = "Howdy Back At Ya!"
MainApp().run()
KV File:
FloatLayout:
BoxLayout:
id: box1
size_hint: 0.8, 0.8
pos_hint: {"center_x": 0.5, "center_y": 0.5}
spacing: dp(33)
orientation: 'vertical'
ScrollView:
id: scroll1
do_scroll_x: False
do_scroll_y: True
#size_hint: 1, None
pos_hint: {'center_x': 0.5, 'center_y': 1}
MDLabel:
id: lbl1
text: "Here we are!"
text_size: self.size
font_size: 18
theme_text_color: "Custom"
text_color: rgba('#f9a825')
valign: "center"
halign: "justify" # justifies text in label box
multiline: True
pos_hint: {'center_x': 0.5, 'center_y': 0.5}
size_hint_y: None
height: self.texture_size[1]
Button:
id: btn
text: "Change"
on_release: app.press_btn()
Button:
id: btn2
text: "Change 2"
on_release: app.press_btn2()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
