Kivy CheckBox looks like a solid black box (not a check box)

I am creating a BoxLayout widget (orientation = 'horizontal') containing three widgets inside it, a shortcut, a text box and a check box.

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) 

As a result, the following widget (thisRow) is created:

enter image description here

After checking the checkbox ...

enter image description here

The rightmost black box is actually a flag and works functionally, but the user does not know that it is actually a flag. I would expect a smaller empty square in the middle, as shown in the figures here.

How to get a traditional flag (smaller empty square box)? Or in general, how can I make it more obvious that the field is a flag, and not just an empty label?

thanks

+5
source share
3 answers

This is a really interesting question, and Malonge tried it in a good way. Right now (1.9.2-dev) there is still a fixed size on the CheckBox well, call it the background. This is the image that Widget takes from the atlas and changes if the state changes. Therefore, until now there was no clear way to do this. Here is an example. Soon, the wizard will have the CheckBox(color=[r,g,b,a]) option CheckBox(color=[r,g,b,a]) . Thanks;)

 from kivy.lang import Builder from kivy.base import runTouchApp from kivy.uix.boxlayout import BoxLayout Builder.load_string(''' <CheckBoxBG>: Label: TextInput: CheckBox: canvas.before: Color: rgb: 1,0,0 Rectangle: pos:self.center_x-8, self.center_y-8 size:[16,16] Color: rgb: 0,0,0 Rectangle: pos:self.center_x-7, self.center_y-7 size:[14,14] ''') class CheckBoxBG(BoxLayout):pass runTouchApp(CheckBoxBG()) 
+3
source

It appears that the smaller checkbox is hidden when the background color is black. Here is an example of a red background.

enter image description here

This is not ideal because I like the black background, but I can work with it at the moment. If someone knows how to do this with a black background, that would be great. Thanks you

+1
source

Alternatively, to change the background of the flags, you can use another image from the atlas or create images and then upload them:

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

In Kivy 1.9.2.dev0 (and, obviously, since version 1.9.0) you can change the background image of the flags. By default, Kivy uses these atlas * backgrounds.

 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. 

You can look here for all the attributes:

* Atlas is a package of several textures, which reduces the number of downloaded images and speeds up the loading of the application. You see a preview of the atlas in Python Install Folder\Lib\site-packages\kivy\data\images\defaulttheme-0.png

+1
source

All Articles