how to maximize scrollbar in Kivy python?(如何在 Kivy python 中最大化滚动条?)
问题描述
我在 kivy 中使用 multiTab.如何放大滚动条,以便鼠标可以移动(up_down)滚动条.我正在使用 BoxLayout 和 RecycleView.下面的代码使用的是 gridLayout,但不在 BoxLayout 中:
I am using multiTab in kivy. How to enlarge the scrollbar so that scrollbar can be moved(up_down) by mouse. I am using BoxLayout and RecycleView. The code below was working with gridLayout, but not in BoxLayout:
layout.bind(minimum_height=layout.setter('height'))
推荐答案
这是一个如何扩展 ScrollView 以获得可拖动滑块的示例.
Here is an example of how to extend ScrollView to also get a dragable slider.
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.lang import Builder
from kivy.uix.label import Label
Builder.load_string("""
<ScrollSlider>:
ScrollView:
id: scrlvw
bar_width: 0
GridLayout:
id: grid
size_hint_y:None
cols:1
height: self.minimum_height
scroll_y: slider.value
on_touch_move: slider.value = self.scroll_y
Slider:
size_hint_x: None
width: root.width*0.2
id: slider
min: 0
max: 1
orientation: 'vertical'
value: scrlvw.scroll_y
on_value: scrlvw.scroll_y = self.value
""")
class ScrollSlider(BoxLayout):
def custom_add(self, widget):
self.ids.grid.add_widget(widget)
class MyApp(App):
def build(self):
scrollslider = ScrollSlider()
for i in range(1, 100):
scrollslider.custom_add(Label(text=str(i), height=100, size_hint_y=None))
return scrollslider
if __name__ == '__main__':
MyApp().run()
你需要使用custom_add在ScrollSlider中添加widget或者在kivy中添加到GridLayout中.
You need to use the custom_add to add widgets in the ScrollSlider or add them to the GridLayout in kivy.
我从@Edvardas Dlugauskas 提供的链接中获得了一些灵感.
I took some inspiration from the link @Edvardas Dlugauskas provided.
您提供的代码不适用于 BoxLayout,因为 BoxLayout 只占用其父级的大小.为了能够滚动,您需要将 sth 添加到比 ScrollView 本身大的 ScrollView 中.
The code you provided does not work with BoxLayout because BoxLayout just takes the size of its parent. To be able to scroll you need to add sth into ScrollView which is larger than the ScrollView itself.
这篇关于如何在 Kivy python 中最大化滚动条?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 Kivy python 中最大化滚动条?
基础教程推荐
- numpy float:比算术运算中内置的慢 10 倍? 2022-01-01
- 将 x 轴刻度更改为自定义字符串 2022-01-01
- 与常规 dict 相比,Python manager.dict() 非常慢 2022-01-01
- 由Python将MP3转换为MIDI(类型错误:无法加载插件:mtg-Melodia:Melodia) 2022-01-01
- pyserial - 可以从线程 a 写入串行端口,是否阻塞从线程 b 读取? 2022-01-01
- 用 Python 编写 Fortran 无格式文件 2022-01-01
- Discord.py 缺少必需的参数 2022-01-01
- 使用生成器和迭代器时 Python 多循环失败 2022-01-01
- 尝试制作WhatsApp机器人 2022-01-01
- 在 Celery 工作人员中捕获 Heroku SIGTERM 以优雅地关 2022-01-01
