Looking at your video, I would suggest setting scroll_y to 1 after repopulating the scrollview.
Not related to your problem – but you can simplify clear_widgets by using the clear_widgets method.
--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/cfc4e6a6-884a-43ba-b481-5ae573733614n%40googlegroups.com.
I don't know why scroll_y 1 or 0 is important for my bug?
It looks to me like the ScrollView is set to a ‘middle value’ the widgets are then removed, and scroll is in the incorrect position. My thought was that resetting the scroll_y value would reposition all of the widgets in the scroll view.
Here is an example that shows a scroll view, and changes the scroll_y value.
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.button import Button
from kivy.uix.scrollview import ScrollView
kv = """
<ScrollButton>:
size_hint_y: None
height: dp(48)
<SV>:
BoxLayout:
orientation: 'vertical'
id: scroll_box
size_hint_y: None
height: self.minimum_height
BoxLayout:
orientation: 'vertical'
spacing: dp(10)
Label:
text: 'Scroll Reset Example'
size_hint_y: None
height: dp(30)
SV:
id: sv
BoxLayout:
size_hint_y: None
height: dp(48)
Button:
text: 'Set scroll_y = 0'
on_release: sv.scroll_y = 0
Button:
text: 'Set Scroll_y = 1'
on_release: sv.scroll_y = 1
Button:
text: 'Clear widgets'
on_release: sv.ids.scroll_box.clear_widgets()
Button:
text: 'Add widgets'
on_release: sv.add_buttons()
Button:
text: 'Add & Scroll'
on_release:
sv.add_buttons()
sv.scroll_y = 1
"""
class ScrollButton(Button):
pass
class SV(ScrollView):
def add_buttons(self):
if not self.ids.scroll_box.children:
for i in range(100):
self.ids.scroll_box.add_widget(ScrollButton(text=f'Button {i}'))
class ScrollApp(App):
def build(self):
return Builder.load_string(kv)
def on_start(self):
self.root.ids.sv.add_buttons()
ScrollApp().run()
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/f90724c7-c889-45fa-95ce-001fff99a263n%40googlegroups.com.
I wonder that Can i enforce the required order with Clock.scheule_once()?
Create a new method for your Clock.schedule_once().
…
Clock.schedule_once(self.two_methods)
def two_methods(self, dt):
fun_one() # these will be called in order
fun_two()
From: Mecra Yavcin
Sent: Thursday, February 9, 2023 12:43 AM
To: Kivy users support
Subject: Re: [kivy-users] Kivy Scrolling Causes to Be Disappear of ResultsForaWhile After Removing (Clearing) and Creating Widgets
Thanks very much. Example code was usefull me and i also fixed my problem. I deleted all Clock.scheule_once() codes and i used mythread =hreading.Thread(target=self.clear_widgets)
mythread.start() to enforce the required order for all defs(). I wonder that Can i enforce the required order with Clock.scheule_once()?
Thanks very much
8 Şubat 2023 Çarşamba tarihinde saat 19:29:38 UTC+3 itibarıyla ElliotG şunları yazdı:
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/cbed50af-e6d0-409b-ba61-eefed72c8907n%40googlegroups.com.