大家好,我是这个网站的新手,如果我做错了事,我要提前道歉,来自kivy-garden的ScrollLabel在我尝试使用它时给我一个错误
基本上,我尝试制作一个控制台日志,我需要能够在文本框填充时滚动它,我尝试了scrollview小部件,但是当我显示太多文本时它会产生黑屏
即使我使用示例ScrollLabel,我也会遇到相同的错误
我收到的错误:

 Traceback (most recent call last):
   File "/home/fodderpod/Apps/FPCU-02/GUI/main.py", line 184, in <module>
     presentation = Builder.load_file("mainScreenHolder.kv")
   File "/usr/local/lib/python3.7/dist-packages/kivy/lang/builder.py", line 301, in load_file
     return self.load_string(data, **kwargs)
   File "/usr/local/lib/python3.7/dist-packages/kivy/lang/builder.py", line 405, in load_string
     rule_children=rule_children)
   File "/usr/local/lib/python3.7/dist-packages/kivy/lang/builder.py", line 657, in _apply_rule
     root=rctx['ids']['root'], rule_children=rule_children)
   File "/usr/local/lib/python3.7/dist-packages/kivy/uix/widget.py", line 469, in apply_class_lang_rules
     rule_children=rule_children)
   File "/usr/local/lib/python3.7/dist-packages/kivy/lang/builder.py", line 538, in apply
     rule_children=rule_children)
   File "/usr/local/lib/python3.7/dist-packages/kivy/lang/builder.py", line 659, in _apply_rule
     child, crule, rootrule, rule_children=rule_children)
   File "/usr/local/lib/python3.7/dist-packages/kivy/lang/builder.py", line 654, in _apply_rule
     child = cls(__no_builder=True)
   File "kivy/_event.pyx", line 188, in kivy._event.EventDispatcher.__cinit__
   File "kivy/properties.pyx", line 447, in kivy.properties.Property.link
   File "kivy/properties.pyx", line 632, in kivy.properties.NumericProperty.init_storage
   File "kivy/properties.pyx", line 418, in kivy.properties.Property.init_storage
   File "kivy/properties.pyx", line 655, in kivy.properties.NumericProperty.convert
   File "kivy/properties.pyx", line 665, in kivy.properties.NumericProperty.parse_str
 ValueError: could not convert string to float:
^C
[11]+  Exit 1                  python3 /home/fodderpod/Apps/FPCU-02/GUI/main.py


我无法发布我的代码,但这是scrollview wich的示例代码会产生相同的错误


__version__ = "1.0"

from kivy.app import App
from kivy.lang import Builder
from kivy.garden.scrolllabel import ScrollLabel

LOREM = """Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur nec arcu accumsan, lacinia libero sed, cursus nisi. Curabitur volutpat mauris id ornare finibus. Cras dignissim arcu viverra, bibendum est congue, tempor elit. Vivamus luctus sapien sapien, id tincidunt eros molestie vitae. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut commodo eget purus vel efficitur. Duis facilisis ex dolor, vel convallis odio pharetra quis. Vivamus eu suscipit tortor. Proin a tellus a nisl iaculis aliquam. Nam tristique ipsum dui, ut faucibus libero lacinia id. Pellentesque eget rhoncus justo, quis interdum eros. Suspendisse felis lorem, gravida in orci ac, auctor malesuada turpis. Fusce dapibus urna dolor, id viverra enim semper a. Proin dignissim neque quis ante commodo feugiat.
Duis dictum sagittis urna nec dapibus. Vestibulum ac elit vel nunc euismod lobortis. Vivamus sit amet tortor in diam consectetur ultrices vitae vulputate leo. Aenean vehicula orci leo, eget fringilla enim condimentum eget. Sed sapien lacus, vulputate nec ligula eget, luctus feugiat risus. Nullam ultricies quam ac metus imperdiet, eget scelerisque dolor commodo. Ut nec elementum orci. Cras massa lacus, consectetur varius est a, congue pulvinar magna. Proin nec sapien facilisis, tristique turpis vel, malesuada leo. Phasellus faucibus justo vel risus tristique, in laoreet ligula vestibulum. Vestibulum varius eget nibh nec convallis. Morbi eu diam at turpis mollis hendrerit. Aenean sed turpis lectus.
Suspendisse pharetra ligula nec faucibus mattis. Aliquam et felis eget augue efficitur aliquam viverra ut tellus. Aliquam sagittis ut sapien venenatis condimentum. Quisque in turpis ac nisi vehicula commodo vel porttitor erat. Maecenas lobortis, sapien dictum congue gravida, nulla urna ultricies lorem, at tincidunt ex arcu nec eros. Maecenas egestas a augue sit amet euismod. Praesent ut sapien metus. Curabitur lorem erat, consectetur quis rhoncus quis, tristique ac ligula. Suspendisse justo magna, cursus id mauris et, lacinia egestas neque.
Suspendisse bibendum sit amet est eget ullamcorper. Duis pellentesque tristique nisi. Donec id dolor eget arcu lobortis sollicitudin vel et justo. Vivamus vel risus eget felis condimentum tempus ac sed dui. Donec placerat risus quis metus auctor sagittis. Pellentesque vel sem dolor. Praesent erat eros, facilisis placerat ultrices et, interdum quis risus. Donec eleifend risus dapibus, laoreet felis ut, fermentum neque. Aenean purus elit, congue non tempus quis, dictum quis metus. Maecenas finibus rutrum bibendum. Ut vestibulum dapibus felis vel luctus. Aliquam vitae consequat eros, quis ultricies tortor. Quisque eu accumsan erat, id commodo nisi.
Etiam nec risus porttitor, placerat est et, facilisis diam. Etiam vel feugiat ligula. Aliquam at quam congue, lacinia velit nec, congue nibh. In varius quis elit vel sollicitudin. Vivamus molestie elementum ipsum et vehicula. Etiam non augue quis tortor ultrices maximus. Etiam vel blandit nibh. Nullam facilisis posuere erat vel mattis. Vestibulum mattis condimentum purus efficitur vehicula. Aliquam consequat interdum eros eu semper. Etiam feugiat, erat at tempor tincidunt, odio eros maximus sapien, sit amet lacinia nibh tortor quis dui. In hac habitasse platea dictumst.
"""

KV_EXAMPLE = """
#: import LOREM __main__.LOREM
BoxLayout:
    orientation: "vertical"
    Label:
        text: "ScrollLabel Demo"
        size_hint_y: None
        height: "48sp"

    ScrollLabel:
        id: sl
        text: LOREM * int(sl_count.value)
        font_size: sl_fontsize.value

    BoxLayout:
        size_hint_y: None
        height: "48sp"
        Label:
            text: "Text count"
            size_hint_x: None
            width: self.texture_size[0] + dp(48)
        Slider:
            id: sl_count
            min: 1
            max: 20
            value: 1
            step: 1

    BoxLayout:
        size_hint_y: None
        height: "48sp"
        Label:
            text: "Font size"
            size_hint_x: None
            width: self.texture_size[0] + dp(48)
        Slider:
            id: sl_fontsize
            min: sp(8)
            max: sp(100)
            value: sp(14)

    BoxLayout:
        size_hint_y: None
        height: "48sp"
        Label:
            text: "Alignment"
            size_hint_x: None
            width: self.texture_size[0] + dp(48)
        Button:
            text: "Left"
            on_press: sl.halign = "left"
        Button:
            text: "Center"
            on_press: sl.halign = "center"
        Button:
            text: "Right"
            on_press: sl.halign = "right"

"""


class TestScrollLabel(App):
    def build(self):
        return Builder.load_string(KV_EXAMPLE)

if __name__ == "__main__":
    TestScrollLabel().run()

最佳答案

我提交了PR版本,其中包含了kivy 1.10+所需的修复程序。
在接受之前(存储库过去4年一直处于闲置状态),您可以从here获取固定版本。

您也可以在项目中复制(并重命名)__init__.py并仅导入ScrollLabel

10-07 15:07