# How to dynamically show/hide panel elements using python?

Say I have a property set on a scene, like so:

bpy.types.Scene.is_enabled = bpy.props.BoolProperty(default=False)


Then I've got a panel like the following:

class SomePanel(bpy.types.Panel):
bl_idname      = "the_panel"
bl_label       = "Panel with some controls"
bl_space_type  = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context     = "object"

def draw(self, context):
layout = self.layout
scene = context.scene

layout.prop(scene, "is_enabled")


Now what I would like to do is to render an operator or some other control in the panel only if the property of scene is_enabled is set to true?

How can I do that?

The solution was so trivial I didn't expect it to be. It's a matter of simply adding a conditional to the panel draw function:

class SomePanel(bpy.types.Panel):
bl_idname      = "the_panel"
bl_label       = "Panel with some controls"
bl_space_type  = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context     = "object"

def draw(self, context):
layout = self.layout
scene = context.scene

layout.prop(scene, "is_enabled")

if scene.is_enabled:
layout.operator("object.select_random") # As an example.