简体   繁体   中英

kivy scroll view just shows black screen

I'm currently learning kivy and was following a tutorial, while following the tutorial I ran into a problem where uppon running my code only a black screen appears

this is what my.py file looks like:

from kivy.uix.widget import Widget
from kivy.uix.stacklayout import StackLayout
from kivy.uix.button import Button
from kivy.metrics import dp
from kivy.app import App


class stack_layout_example(StackLayout):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        """
        # orientation without the kv
        self.orientation = "lr-bt"
        """
        for i in range(0, 100):
            size = 100
            button = Button(
                text = str(i+1),
                size_hint=(None, None),
                #    ( width , height )
                size=(size, size)
            )
            self.add_widget(button)

class the_labApp(App):
    pass

the_labApp().run()

and this is my.kv file:

scroll_view_example:

<scroll_view_example@ScrollView>:
    stack_layout_example:

<stack_layout_example>:

You're missing the build method in the the_labApp app. It should be like the following code snippet:

class the_labApp(App):
    def build(self):
        return stack_layout_example()

截屏

Thank You very much for your answers guys... I already found the solution in the kivy discord

i just re-arrange the.kv file to

<ScrollViewExample@ScrollView>:
    StackLayoutExample:
        size_hint: 1, None
        height: self.minimum_height

<StackLayoutExample>:

ScrollViewExample:

also the kv looks a bit different now because it now follows pep8(i think)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM