Kivy CheckBox看起来像纯黑盒子(不是复选框)

时间:2015-04-16 20:38:33

标签: python kivy

我正在创建一个BoxLayout小部件(orientation ='水平'),其中包含三个小部件,一个标签,一个文本框和一个复选框。

thisRow = BoxLayout(orientation='horizontal')
l = Label(text='Enter plate 1:\n(Plate #)')
t = TextInput(text = 'this is a text box')
c = CheckBox()
thisRow.add_widget(l)
thisRow.add_widget(t)
thisRow.add_widget(c)

这会产生以下小部件(thisRow):

enter image description here

选中此框后......

enter image description here

最右边的黑匣子实际上是复选框,并且功能正常,但是用户无法知道它实际上是一个复选框。我希望中间有一个较小的空方块,如图here.

所示

如何获得传统的复选框图像(较小的空方框)?或者一般来说,我怎样才能让盒子更明显的是复选框而不仅仅是一个空标签?

谢谢

3 个答案:

答案 0 :(得分:4)

这是一个非常有趣的问题,Malonge以一种很好的方式尝试了它。现在(1.9.2-dev)在android:largeHeap="true" 上仍有固定的大小,称之为背景。这是CheckBox从图集中获取的图像,如果状态发生变化则会发生变化。因此,在now之前,没有明确的方法可以做到这一点。这是一个例子。很快掌握了Widget选项。谢谢;)

CheckBox(color=[r,g,b,a])

答案 1 :(得分:1)

当背景颜色为黑色时,看起来隐藏了较小的复选框。这是一个红色背景的例子。

enter image description here

这不太理想,因为我喜欢黑色背景,但我现在可以使用它。如果有人知道如何用黑色背景做到这一点,这将是伟大的。谢谢

答案 2 :(得分:1)

或者,要更改复选框背景,您可以使用图集中的其他图像或创建图像,然后加载它们:

mycheckbox= CheckBox(
background_checkbox_normal ='tlas://data/images/defaulttheme/button_disabled'
background_checkbox_down = 'my_checkboxes_checked.png'
)   

在Kivy 1.9.2.dev0中(显然自版本1.9.0开始),您可以更改复选框的背景图像。默认情况下,Kivy使用atlas *。

中的这些背景
background_checkbox_normal = StringProperty('atlas://data/images/defaulttheme/checkbox_off') #when the checkbox is not active.
background_checkbox_down = StringProperty('atlas://data/images/defaulttheme/checkbox_on') # when the checkbox is active.
background_checkbox_disabled_normal = StringProperty('atlas://data/images/defaulttheme/checkbox_disabled_off') #when the checkbox is disabled and not active.
background_checkbox_disabled_down = StringProperty('atlas://data/images/defaulttheme/checkbox_disabled_on') #when the checkbox is disabled and active.

您可以查看所有属性here

*图集是一个包含多个纹理的包,可减少加载的图像数量并加快应用程序的加载速度。您已在Python Install Folder\Lib\site-packages\kivy\data\images\defaulttheme-0.png

中看到地图集的预览