如何在kv文件中编写(编辑)长标签文本?

时间:2016-02-05 22:01:49

标签: python text label kivy

如何在.kv文件中编写与标签相关的长文本(> 80个字符)? 例如:

Label:
    Text: 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. \
           Aenean commodo ligula eget dolor. Aenean massa. Cum sociis \
           natoque penatibus et magnis dis parturient montes, nascetur.'

此示例生成错误。我尝试了各种格式,也无法在论坛中找到解决方案。

1 个答案:

答案 0 :(得分:0)

虽然assignments toproperties must be on one line,但它们当然可以包含超过80个字符。另一个选择是在python文件中定义文本并将其导入kv文件。

示例:

#:import fix fixtures
<Label>:
    text_size: (self.parent.width, self.height)
    width: self.parent.width

GridLayout:
    rows: 2
    Label:
        text: 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur.'
    Label:
        text: fix.text

fixtures.py

text = 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. \
Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque \
penatibus et magnis dis parturient montes, nascetur.'