Last active
January 9, 2024 11:50
-
-
Save wishrohitv/8ae42f9ee07e1dc8d70c1f90d56045e1 to your computer and use it in GitHub Desktop.
minimal kivy and python code to use multiple widget using for loop via ScrollView
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from kivy.app import App | |
from kivy.lang.builder import Builder | |
from kivy.uix.button import Button | |
from kivy.uix.boxlayout import BoxLayout | |
from kivy.properties import StringProperty | |
kv = """ | |
<CWidget>: | |
text: root.name | |
background_color: "red" | |
size_hint: 1, None | |
height: "60dp" | |
<SV>: | |
BoxLayout: | |
orientation: "vertical" | |
Label: | |
id: label | |
text:'Scroll View' | |
size_hint: 1, .3 | |
font_size: "25sp" | |
ScrollView: | |
do_scroll_y: True | |
do_scroll_x: False | |
BoxLayout: | |
orientation: "vertical" | |
size_hint_y: None | |
height: self.minimum_height | |
padding: 10 | |
BoxLayout: | |
orientation: "vertical" | |
id: wd | |
size_hint_y: None | |
height: self.minimum_height | |
""" | |
class CWidget(Button): | |
name = StringProperty() | |
class SV(BoxLayout): | |
def __init__(self, **kwargs): | |
super().__init__(**kwargs) | |
for i in range(20): | |
self.ids.wd.add_widget(CWidget( | |
name = str(i) | |
)) | |
Builder.load_string(kv) | |
class Scroll(App): | |
def build(self): | |
return SV() | |
Scroll().run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment