3
$\begingroup$

So here is a example Panel and adding a boolean,

import bpy
from bpy.props import BoolProperty

bpy.types.Scene.Boolean= BoolProperty(
    name="Boolean",
        description="Example",
        default = True)

class Example_Panel(bpy.types.Panel):
    bl_label = "Example"
    bl_category = "Example"
    bl_space_type = "VIEW_3D"
    bl_region_type = "UI"
   

    def draw(self, context):
        layout = self.layout
        sce = context.scene
        layout.prop(sce, "Boolean")

def register():
    bpy.utils.register_class(Example_Panel)

def unregister():
    bpy.utils.unregister_class(Example_Panel)

if __name__ == "__main__":
    register() 

so that would give a check like this,

Boolean Example

and to add a icon,

layout.prop(sce, "Boolean", icon = 'CHECKMARK')

that would give this,

Icon

so I don't want an icon and at the same time I want a a button like the latter picture.

So far, I do this to not put a Icon to my booleans,

layout.prop(sce, "Boolean", icon = 'BLANK1')

It gives this,

Solution for now

But there is a offset to the right which I don't want, so how would I do this?

$\endgroup$

1 Answer 1

3
$\begingroup$

In the API Documentation it says:

toggle (int in [-1, 1], (optional)) – Use toggle widget for boolean values, or a checkbox when disabled (the default is -1 which uses toggle only when an icon is displayed)

So you can use:

layout.prop(sce, "Boolean", toggle = 1)

Which gives you exactly what you want:

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.