Label 的 Kivy ScrollView 不会滚动
Kivy ScrollView of Label won't scroll
我在一个ScrollView里面有一个Label,希望当(多行)文本占用太多行时,用户可以上下滚动,当行太长时,用户可以向左滚动&正确的。而且我无法让它滚动。这是我的 Builder 字符串的相关部分:
ScrollView:
id: scrollLayout
size_hint_y: 0.9
Label:
id: sortFilesDisplay
size_hint_y: 0.9
text: 'Drag\n in\n files\n to\n be\n sorted\n yea\n go\n now\n testing\n please\n work\n now\help'
我读过 Kivy docs on ScrollView,说我需要指定 size_hints 之一才能启用滚动。我已经阅读了一些关于让 ScrollView 工作的 SO 帖子:
- ScrollView widget not scolling in kivy
- Kivy -- scroll view not working. And and how add chat users on side pane
但它们都涉及嵌入某种布局(例如 GridLayout),但我没有嵌入布局,只是嵌入一个标签。我已尝试将 minimum_height 设置为我在这些帖子中看到的各种内容,但仍然没有效果。
那两个 size_hint_y 在那里只是为了按照指示去做;我不需要它们。还尝试将它们设置为 None。
有什么想法吗?
此外,文本的静态字符串并不是我最终想要的。我希望标签在字符串更改时保持可滚动(当用户放入新的文件列表时),但我认为 'dynamic' 操作可能是个问题,所以现在我 'retreated' 尝试静态字符串。
为了使 Label
可滚动,它应该大于 ScrollView
小部件,因此您需要将 size_hint
设置为 None
并将标签大小绑定到字体大小。例如:
test.kv:
ScrollView:
Label:
id: sortFilesDisplay
size_hint: None, None # <<<<<<<<<<
size: self.texture_size # <<<<<<<<<<
text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit,\n sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\n\n" * 20
main.kv
from kivy.app import App
from kivy.config import Config
Config.set('graphics', 'width', '300')
Config.set('graphics', 'height', '200')
class TestApp(App):
pass
if __name__ == '__main__':
TestApp().run()
我在一个ScrollView里面有一个Label,希望当(多行)文本占用太多行时,用户可以上下滚动,当行太长时,用户可以向左滚动&正确的。而且我无法让它滚动。这是我的 Builder 字符串的相关部分:
ScrollView:
id: scrollLayout
size_hint_y: 0.9
Label:
id: sortFilesDisplay
size_hint_y: 0.9
text: 'Drag\n in\n files\n to\n be\n sorted\n yea\n go\n now\n testing\n please\n work\n now\help'
我读过 Kivy docs on ScrollView,说我需要指定 size_hints 之一才能启用滚动。我已经阅读了一些关于让 ScrollView 工作的 SO 帖子:
- ScrollView widget not scolling in kivy
- Kivy -- scroll view not working. And and how add chat users on side pane
但它们都涉及嵌入某种布局(例如 GridLayout),但我没有嵌入布局,只是嵌入一个标签。我已尝试将 minimum_height 设置为我在这些帖子中看到的各种内容,但仍然没有效果。
那两个 size_hint_y 在那里只是为了按照指示去做;我不需要它们。还尝试将它们设置为 None。
有什么想法吗?
此外,文本的静态字符串并不是我最终想要的。我希望标签在字符串更改时保持可滚动(当用户放入新的文件列表时),但我认为 'dynamic' 操作可能是个问题,所以现在我 'retreated' 尝试静态字符串。
为了使 Label
可滚动,它应该大于 ScrollView
小部件,因此您需要将 size_hint
设置为 None
并将标签大小绑定到字体大小。例如:
test.kv:
ScrollView:
Label:
id: sortFilesDisplay
size_hint: None, None # <<<<<<<<<<
size: self.texture_size # <<<<<<<<<<
text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit,\n sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\n\n" * 20
main.kv
from kivy.app import App
from kivy.config import Config
Config.set('graphics', 'width', '300')
Config.set('graphics', 'height', '200')
class TestApp(App):
pass
if __name__ == '__main__':
TestApp().run()