python - Kivy ListItemButton - 如何增加按钮尺寸的高度?

标签 python listview kivy

我在代码中使用 ListItemButton。但我无法更改列表项按钮的大小。 请有人指导如何更改 ListItemButton 的按钮大小。

我尝试使用“size_hint_y: None”和“height: '48dp”来实现此目的,但仍然不成功

下面您可以看到示例代码。

main.py

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout

class TestRoot(BoxLayout):
    pass


class TestApp(App):
    pass


if __name__ == '__main__':
    TestApp().run()

测试.kv

#: import ListItemButton kivy.uix.listview.ListItemButton
#: import ListAdapter kivy.adapters.listadapter.ListAdapter

TestRoot:
    orientation: "vertical"
    Label:
        text: "How to the change the button height of ListItemButton?"
    ListView:
        adapter: ListAdapter(data = ['0','1','2','3','4','5','6','7','8','9'], cls = ListItemButton)

列表项按钮上的 Kivy 问题

最佳答案

您可以在 main.py 中创建一个由 ListAdapter 继承的类,例如:

from kivy.uix.listview import ListItemButton
....
class TestListItemButton(ListItemButton):
    def __init__(self, **kwargs):
        super(TestListItemButton, self).__init__(**kwargs)
        self.height = "100dp"

然后更改适配器以继承正确的类

adapter: ListAdapter(data = ['0','1','2','3','4','5','6','7','8','9'], cls = TestListItemButton)

现在你可以将 self.height 更改为你想要的任何值

关于python - Kivy ListItemButton - 如何增加按钮尺寸的高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36734799/

相关文章:

python - Azure Durable Function 可以运行多长时间?

python - Python 中自定义错误处理程序的正确命名范围

python - 在 Python 脚本中比较 SNMP OID

java - 如何用while循环填充数组?

c# - 以编程方式使用 ListView 转到另一个页面?

android - App kivy连接不上mysql数据库

python请求: PUT request to azure fails with 415 error

android - ListView 中图像的低 FPS

android - key 错误 : 'ANDROID_APP_PATH'

python - Kivy:chow获取FloatLayout中心坐标