[英]How to create a scrollable floatlayout on Kivy?
I want to create a scrollable floatlayout .我想创建一个可滚动的floatlayout 。
I found this code on the internet, to create a scrollable Gridlayout :我在互联网上找到了这段代码,用来创建一个可滚动的Gridlayout :
from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.uix.floatlayout import FloatLayout
from functools import partial
from kivy.uix.scrollview import ScrollView
from kivy.uix.slider import Slider
from kivy.uix.button import Button
class Board(FloatLayout):
def __init__(self, **kwargs):
super(Board, self).__init__(**kwargs)
scrlv = ScrollView(size_hint=(0.9,0.95))
layout2 = GridLayout(cols=1, size_hint_y=None)
layout2.bind(minimum_height=layout2.setter('height'))
scrlv.add_widget(layout2)
s = Slider(min=0, max=1, value=25, orientation='vertical', step=0.01, size_hint=(0.1, 0.95))
scrlv.bind(scroll_y=partial(self.slider_change, s))
s.bind(value=partial(self.scroll_change, scrlv))
self.add_widget(scrlv)
self.add_widget(s)
for i in range(1, 301):
btn = Button(text=str(i), size_hint_y=None, height=60, valign='middle', font_size=12)
btn.text_size = (btn.size)
layout2.add_widget(btn)
def scroll_change(self, scrlv, instance, value):
scrlv.scroll_y = value
def slider_change(self, s, instance, value):
if value >= 0:
s.value = value
class TestApp(App):
def build(self):
self.title = 'Test'
return Board()
TestApp().run()
It works fine, but when i tried to convert it into floatlayout like this:它工作正常,但是当我尝试将其转换为这样的floatlayout 时:
from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.uix.floatlayout import FloatLayout
from functools import partial
from kivy.uix.scrollview import ScrollView
from kivy.uix.slider import Slider
from kivy.uix.button import Button
class Board(FloatLayout):
def __init__(self, **kwargs):
super(Board, self).__init__(**kwargs)
scrlv = ScrollView(size_hint=(0.9, 0.95))
layout2 = FloatLayout(size_hint_y=None)
layout2.bind(minimum_height=layout2.setter('height'))
scrlv.add_widget(layout2)
s = Slider(min=0, max=1, value=25, orientation='vertical', step=0.01, size_hint=(0.1, 0.95))
scrlv.bind(scroll_y=partial(self.slider_change, s))
s.bind(value=partial(self.scroll_change, scrlv))
self.add_widget(scrlv)
self.add_widget(s)
for i in range(1, 301):
btn = Button(text=str(i), size_hint_y=None, height=60, valign='middle', font_size=12)
btn.text_size = (btn.size)
btn.y = 100 - (60*i)
layout2.add_widget(btn)
def scroll_change(self, scrlv, instance, value):
scrlv.scroll_y = value
def slider_change(self, s, instance, value):
if value >= 0:
s.value = value
class TestApp(App):
def build(self):
self.title = 'Test'
return Board()
TestApp().run()
It didn't work and i got this error:它没有用,我收到了这个错误:
layout2.bind(minimum_height=layout2.setter('height'))
File "kivy\_event.pyx", line 427, in kivy._event.EventDispatcher.bind
KeyError: 'minimum_height'
I read about it on the internet and i'm understand that floatlayout doesn't have the attribute "minimum_height", but i don't know what can i replace it with.我在互联网上读到它,我知道 floatlayout 没有属性“minimum_height”,但我不知道我可以用什么来替换它。 Any suggestions?有什么建议?
To make the FloatLayout scroll:要使 FloatLayout 滚动:
None, None
将其 size_hint 设置为None, None
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.