Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from kivy.app import App
- from kivy.lang import Builder
- from kivy.uix.scrollview import ScrollView
- from kivy.uix.button import Button
- from kivy.animation import Animation
- kv = """
- <ScrollButton>:
- size_hint_y: None
- height: dp(48)
- on_release: print(f'{self.text} pressed')
- BoxLayout:
- orientation: 'vertical'
- spacing: dp(10)
- Label:
- text: 'Example of ScrollView Animation'
- size_hint_y: None
- height: 30
- AnimScrollView:
- id: sv
- effect_cls: 'ScrollEffect' # Use 'ScrollEffect', 'DampedScrollEffect' or 'OpacityScrollEffect'
- BoxLayout:
- orientation: 'vertical'
- id: box
- size_hint_y: None
- height: self.minimum_height
- ToggleButton:
- size_hint_y: None
- height: dp(48)
- on_state:
- sv.animate_scroll(self.state)
- self.text = {'normal': 'Start', 'down': 'Stop'}[self.state]
- text: 'Start'
- """
- class ScrollButton(Button):
- pass
- class AnimScrollView(ScrollView):
- def __init__(self, **kwargs):
- super().__init__(**kwargs)
- self.anim = Animation(scroll_y=0, duration=15) + Animation(scroll_y=1, duration=5)
- self.anim.repeat = True
- def animate_scroll(self, toggle_state):
- if toggle_state == 'down':
- self.anim.start(self)
- else:
- self.anim.stop(self)
- class ScrollViewExampleApp(App):
- def build(self):
- return Builder.load_string(kv)
- def on_start(self):
- # create buttons in the boxlayout that is in the scrollview
- for i in range(20):
- self.root.ids.box.add_widget(ScrollButton(text=f'Button {i}'))
- ScrollViewExampleApp().run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement