Kivy Scrolling Causes to Be Disappear of Results For a While After Removing (Clearing) and Creating Widgets

78 views
Skip to first unread message

Mecra Yavcin

unread,
Feb 7, 2023, 5:25:49 AM2/7/23
to Kivy users support
Kivy Scrolling Causes A Bug After Removing (Clearing) and Creating Widgets I will share full code: So You can test on VS Code. 

Elliot Garbus

unread,
Feb 7, 2023, 9:31:08 AM2/7/23
to kivy-...@googlegroups.com

Looking at your video, I would suggest setting scroll_y to 1 after repopulating the scrollview.

See: https://kivy.org/doc/stable/api-kivy.uix.scrollview.html?highlight=scrollview#kivy.uix.scrollview.ScrollView.scroll_y

 

Not related to your problem – but you can simplify clear_widgets by using the clear_widgets method.

https://kivy.org/doc/stable/api-kivy.uix.widget.html?highlight=clear_widgets#kivy.uix.widget.Widget.clear_widgets

--
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.

 

Mecra Yavcin

unread,
Feb 7, 2023, 12:44:54 PM2/7/23
to Kivy users support
First of all thank you.
I am not as good as in Python and Kivy.
All i studied 500 hours on Python and 15 hours on Kivy.
So i need your support ElliotG.

About document
Y scrolling value, between 0 and 1. If 0, the content’s bottom side will touch the bottom side of the ScrollView. If 1, the content’s top side will touch the top side.
This property is controlled by ScrollView only if do_scroll_y is True.
scroll_y is a NumericProperty and defaults to 1.

I don't know why scroll_y 1 or 0 is important for my bug?

I did not exactly understand  'setting scroll_y to 1 after repopulating the scrollview'
I thought how to do that.
I tried something and but not worked.

Before i had bought a Kivy course from udemy and i tried Property on this project to solve this.
What i did? 

1) On document ' This property is controlled by ScrollView only if do_scroll_y is True. So
     i added  do_scroll_y:True to Scrollview in KV file
2) i added  scroll_y: root._number_ under Scrollview: in KV file
3) i added _number_ = NumericProperty(0) inside Main Class :  class Test(BoxLayout):
4) Lastly i tried add self._number_ = int(1) command inside some def()s

(For example

def clear_widgets(self, *args):

        for child in [child for child in self.ids.gridsonuc.children]:
            self.ids.gridsonuc.remove_widget(child)
        self._number_ = int(1)  # i put here

or 

def underOver_hesaplama(self, *args):        

        print("""    
        Welcome to Under Over Goal Statics
        """)

        #self.ids.gridsonuc.remove_widget(box)
       
        for i in range(200):          

            box = BoxLayout(size_hint_y = None, height = dp(50))
            number = WrappedLabel(text = f'{i+1}',font_name = 'Roboto', font_size = dp(15), size_hint = (0.10, 1), halign='center' )
            hometeams = WrappedLabel(text = 'Home Team Name XXX', font_name = 'Roboto', font_size = dp(15), size_hint = (0.225, 1), halign='center', bold = True )
            awayteams = WrappedLabel(text = 'Away Team Name XXX', font_name = 'Roboto', font_size = dp(15), size_hint = (0.225, 1), halign='center', bold = True )
            goals = WrappedLabel(text = '999', font_size = dp(20), font_name = 'Roboto', size_hint = (0.15, 1), halign='center', color= (1, 0.4, 0.769, 1) )
            box.add_widget(number)
            box.add_widget(hometeams)
            box.add_widget(awayteams)
            box.add_widget(goals)
            self.ids.gridsonuc.add_widget(box)
        self._number_ = int(1)  # i put here  cause 'setting scroll_y to 1 after repopulating the scrollview' maybe wrong places.
        self.pop_up.dismiss()

I tried one by one. But not worked.

An idea

I thought if i remove widgets from reverse; may be i can fix the bug but i could not find how can i do that.

def clear_widgets(self, *args):

        for child in [child for child in self.ids.gridsonuc.children]:
            self.ids.gridsonuc.remove_widget(child)

Lastly:

Could you please help me to setting scroll_y to 1 after repopulating the scrollview?
I shared full code on Stackoverflow, maybe you can compose (compile) code for me.
If you help me to fix this bug i will be gratefull.
Thanks very much.
By the way you fixed my second bug (hol on finger scroll_timeout bug) on the other topic so i want to thank you again.


7 Şubat 2023 Salı tarihinde saat 17:31:08 UTC+3 itibarıyla ElliotG şunları yazdı:

Elliot Garbus

unread,
Feb 8, 2023, 11:29:38 AM2/8/23
to kivy-...@googlegroups.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()
Message has been deleted

Elliot Garbus

unread,
Feb 9, 2023, 10:34:10 AM2/9/23
to kivy-...@googlegroups.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ı:

Reply all
Reply to author
Forward
0 new messages