1
我試圖修改ScrollView doc的代碼,使GridLayout中的水平軸上有可滾動的標籤。 GridLayout不應該是可滾動的,只是其中的標籤。Kivy:GridLayout中的水平可滾動標籤
對於我的應用程序,我無法使用kv語言(在.kv或builder中),所以代碼必須在python中。
from kivy.uix.gridlayout import GridLayout
from kivy.uix.label import Label
from kivy.uix.scrollview import ScrollView
from kivy.app import runTouchApp
layout = GridLayout(cols=1, spacing=10)
for i in range(10):
label = Label(text="abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz", height = 30, size_hint_x=None, width=400)
label.bind(minimum_width=label.setter('width'))
root = ScrollView(size_hint=(None, 1), size=(label.width, label.height))
root.add_widget(label)
layout.add_widget(root)
runTouchApp(layout)