Python Kivy复选框看起来像实心黑盒(不是复选框)

Python Kivy复选框看起来像实心黑盒(不是复选框),python,kivy,Python,Kivy,我正在制作一个BoxLayout小部件(方向=‘水平’),其中包含三个小部件,一个标签、一个文本框和一个复选框 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) th

我正在制作一个BoxLayout小部件(方向=‘水平’),其中包含三个小部件,一个标签、一个文本框和一个复选框

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):

选中该框后

最右边的黑框实际上是复选框,在功能上起作用,但是用户无法知道它实际上是一个复选框。我希望中间有一个更小的空方,如图

所示。 如何获得传统的复选框图像(较小的空方框)?或者,一般来说,我怎样才能更清楚地表明该框是一个复选框,而不仅仅是一个空标签


谢谢

背景色为黑色时,较小的复选框看起来会隐藏。下面是一个红色背景的示例


这并不理想,因为我确实喜欢黑色背景,但我现在可以用它跑步了。如果有人知道如何在黑色背景下做这件事,那就太好了。谢谢你

这是一个非常有趣的问题,马龙奇用一种很好的方式尝试了这个问题。现在(1.9.2-dev)在
复选框上仍然有固定的大小。好吧,称它为背景。这是一幅取自atlas的图像,
Widget
,如果状态发生变化,它就会发生变化。因此,直到没有明确的方法来做这件事。这里有一个例子。很快master就会出现
复选框(颜色=[r,g,b,a])
选项。谢谢;)

来自kivy.lang导入生成器
从kivy.base导入runTouchApp
从kivy.uix.boxlayout导入boxlayout
Builder.load_字符串(“”)
:
标签:
文本输入:
复选框:
在以下情况之前:
颜色:
rgb:1,0,0
矩形:
位置:自中心x-8、自中心y-8
尺寸:[16,16]
颜色:
rgb:0,0,0
矩形:
位置:自中心x-7、自中心y-7
尺寸:[14,14]
''')
类CheckBoxBG(BoxLayout):通过
runTouchApp(CheckBoxBG())

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

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.
您可以查看所有属性:


*atlas是一个包含多个纹理的包,可以减少加载的图像数量并加快应用程序加载。您已经在
Python安装文件夹\Lib\site packages\kivy\data\images\defaulttheme-0.png中看到了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.