在下面的答案https://stackoverflow.com/a/56140831/9440453中,如何根据单元格中的值更改单元格的颜色,以及如何根据单元格中的内容调整单元格中的内容或根据内容大小调整单元格的大小。
颜色详情:
如果单元格包含kyle
,则颜色应为red
,如果包含raul
,则颜色应为blue
,依此类推
我们应该编辑哪个属性以使其起作用。
答案 0 :(得分:0)
如何更改文字颜色?
使用color
更改文字颜色
Button是一个Label,其相关联的动作是 按下按钮时触发(或在按下按钮后释放 点击/触摸)。要配置按钮,请使用相同的属性(填充, Label类使用font_size等)和大小调整系统。
color
文本颜色,格式为(r,g,b,a)。
颜色是ListProperty,默认为[1,1,1,1]。
def apply_selection(self, rv, index, is_selected):
''' Respond to the selection of items in the view. '''
self.selected = is_selected
if rv.data[index]['text'].lower() == 'kyle':
self.color = [0, 1, 0, 1] # green colour text
...
elif rv.data[index]['text'].lower() == 'raul':
self.color = [0, 1, 1, 1] # aqua colour text
...
else:
self.color = [1, 1, 1, 1] # default white colour text
...
我如何适应单元格中的内容或根据内容大小调整单元格的大小。
要设置文本内容的大小,请将size
绑定到texture_size
以随文本增长。
texture_size
文本的纹理大小。大小由字体大小和 文本。如果text_size为[None,None],则纹理将为大小 需要适合文本,否则将其裁剪以适合文本 text_size。
当text_size为[None,None]时,可以绑定到texture_size和 按比例重新缩放以适合标签的大小,以便 使文本最大程度地适合标签。
警告
texture_size在texture属性之后设置。如果你听 对于texture的更改,texture_size不会是最新的 您的回叫。改为绑定到texture_size。
<Label>:
size: self.texture_size
<TextInputPopup>:
title: "Popup"
如何根据其中的值更改单元格的颜色
该解决方案需要更改Python脚本。
apply_selection(self, rv, index, is_selected)
中的 kyle 或 raul ,并将rgba分别设置为红色或蓝色。background_color
和background_normal
更改颜色。background_color
背景色,格式为(r,g,b,a)。
这是纹理颜色的乘数。默认纹理 是灰色的,因此只需设置背景颜色即可使颜色更深 结果。要设置纯色,请将background_normal设置为”。
background_color是ListProperty,默认为[1、1、1, 1]。
background_normal
用于默认图形的按钮的背景图像 不按下按钮时的表示形式。
background_normal是StringProperty,默认为 “ atlas:// data / images / defaulttheme / button”。
def apply_selection(self, rv, index, is_selected):
''' Respond to the selection of items in the view. '''
self.selected = is_selected
if rv.data[index]['text'].lower() == 'kyle':
self.background_color = [1, 0, 0, 1] # red background colour
self.background_normal = ''
elif rv.data[index]['text'].lower() == 'raul':
self.background_color = [0, 0, 1, 1] # blue background colour
self.background_normal = ''
else:
self.background_color = [1, 1, 1, 1] # default colour
self.background_normal = 'atlas://data/images/defaulttheme/button' # default