![](/img/trans.png)
[英]How to increase font size or change font style of description in togglebutton widget
[英]How to change the font size of a ListView widget in .kv
我有一个简单的ListView小部件,我将python代码中的列表传递给该小部件。 .kv看起来像这样:
ListView:
id: mylistview
size_hint_y: 0.5
font_size: self.height/5
但是字体大小没有任何作用。 我想我需要(以某种方式)将值传递到列表中的标签,但是使用了非常简单的方法后,我还不太清楚如何。 另外,我发现的所有示例似乎都是特定于Android的?! 谁能告诉我实现这一目标的最简单方法?
编辑:好的,所以根据建议的答案以及大量的Google搜寻,我提出了以下建议:
#:import ListAdapter kivy.adapters.listadapter.ListAdapter
<CustomLabel>:
font_size: 30
<MyPopup>:
GridLayout:
......
ListView:
size_hint: .8, .8
adapter:
ListAdapter(data=["Item #{0}".format(i) for i in range(100)], cls = CustomLabel)
我到过的所有地方都建议这是正确的方法,但这只是给我“ NameError:未定义名称'CustomLabel'”?
据我所知ListView中有没有这样的事情font_size
,所以这都不会基本上没什么。
要获得所需的内容,您需要在小部件内为Label
设置font_size
,然后要做的最简单的方法是制作一个自定义Label
,例如:
#kv
<CustomLabel>:
font_size: <pass value here>
#python
class CustomLabel(Label): pass
要么
#python
class CustomLabel(Label):
font_size = <value>
编辑:哎呀,忘记了适配器的事情。 因此,如果您不想转换参数,基本上可以得到自定义Label
,这样对您来说会更简单。
simple_list_adapter = SimpleListAdapter(
data=["Item #{0}".format(i) for i in range(100)],
cls=CustomLabel)
list_view = ListView(adapter=simple_list_adapter)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.