有人能帮我修一下这个卷轴吗?

2024-04-20 11:12:26 发布

您现在位置:Python中文网/ 问答频道 /正文

当我运行下面的代码时,我不能滚动。我想滚动整个屏幕。你知道吗

我怎样才能做到这一点?你知道吗

from kivy.base import runTouchApp
#kivy.require("1.8.0")
from kivy.uix.floatlayout import FloatLayout
from kivy.lang import Builder
from kivy.config import Config
from kivy.uix.scrollview import ScrollView
from kivy.properties import StringProperty
Config.set('graphics', 'window_state', 'maximized')
Builder.load_string('''
<ScrollableLabel>:
    FloatLayout:
        AsyncImage:
            source:''  #html here               
            allow_stretch: True
            keep_ratio: False
            pos_hint: {"top": 1, 'right':1}
            size_hint: 1, 1 
        AsyncImage:
            source:'' #html here 
            allow_stretch: True               
            keep_ratio: True             
            pos_hint: {"top": 1, 'right':0.13}
            size_hint: 0.15, 0.15    
        Label:
            color: [66/255,134/255,244/255,1]
            height: 40
            font_size: 25
            italic: 1 
            bold: 1
            text: 'testing'
            pos_hint: {"top": 0.96, 'right': 0.24}
            size_hint: 0.1, 0.1
        Label:
            color: [66/255,134/255,244/255,1]
            height: 40
            font_size: 50
            italic: 1 
            bold: 1
            text: 'Testing\\nTesting1\\nTesting2\\nTesting3\\nTesting4'
            pos: root.x, root.y+25
            size_hint: 0.1, 0.1

''')

class ScrollableLabel(ScrollView):
    text = StringProperty('')

if __name__ == "__main__":
    runTouchApp(ScrollableLabel())

所有的东西都会显示,但滚动条不会。你知道吗


Tags: textfromposimportrighttruesizetop
2条回答

我找到了答案。你知道吗

首先,您必须设置size_hint: (1, None),这样您就可以设置height: 40,它决定您可以滚动多长时间。你知道吗

如果不知道要设置多长时间,可以这样设置:height: sum([c.height for c in self.children])

ScrollView的子级必须至少将size_hint的一部分设置为None,否则默认的size_hint: 1,1会使子级的大小与ScrollView相同,因此没有可滚动的内容。因此,只需将ScrollableLabel规则的初始部分更改为:

<ScrollableLabel>:
    bar_width: 20
    FloatLayout:
        size_hint: None, None
        size: 3000, 3000

我对3000的选择是任意的,只是为了确保FloatLayout大于ScrollView。而且bar_width使滚动条更容易查看。你知道吗

相关问题 更多 >