# How to use an if statement inside the draw function to change the UI at runtime?

I have a basic panel and an enum property and I want to change some of the things shown on the panel depending on what is selected in the enum. I tried what was logical and this is what I did:

if self.icons == 'Brightness':
row.prop(scene.ignit_panel, "brightness_icon")
elif self.icons == 'Backlit Keys':
row.prop(scene.ignit_panel, "backlit_keys_icon")
elif self.icons == 'Volume':
row.prop(scene.ignit_panel, "volume_icon")


However it isn't working, it's no longer displaying those things, and everything below it is no longer displaying either. Can this actually be done or am I just showing my noobiness again?

*Update*

I tried playing with the buttons and started getting errors:

Traceback (most recent call last):
File "/Users/MacBook/Documents/Blender/Blends/MacBook/MacBook.blend/macbook_controller.py", line 302, in draw
AttributeError: 'IGLayoutDemoPanel' object has no attribute 'icons'

location: <unknown location>:-1


Thanks, Matthew

• If everything below these lines doesn't show, it often means you have an error in your code, which crashes the draw function and stops the drawing at the line with the error. Take a look at the console (Window > Toggle System Console) to check the output and see if there are any error messages. You might have a typo (scene.ignit_panel ==> scene.ignite_panel?) or some other bug. – TLousky Dec 30 '15 at 21:38
• I use the run script in pyconsole addon and that showed no errors in the console, I checked the spelling against everything before that and thats all fine... – mr-matt Dec 30 '15 at 21:40
• Look at the console when you're hovering over the panel with your mouse (or any time a bit after running the script). Blender redraws and panel when the mouse moves and if there are any errors during drawing they will pop then. Might also help if you edit your question and paste more or all of your code there. – TLousky Dec 30 '15 at 21:55
• Ok, I'll try that, also, how much code should I put in? I have a heck of a lot... – mr-matt Dec 30 '15 at 22:00
• Ok, now we're getting somewhere, I tried playing with the buttons and now I have some errors, could have sworn I'd already tried that! I'll put the error into the description. – mr-matt Dec 30 '15 at 22:01

icons = scene.ignit_panel.icons