Why does defining a value make the script break when the value is not even used The script works perfect

class ObjectShading(bpy.types.Panel):
bl_label = "Shading"
bl_idname = "ObjectShading"
bl_space_type = 'VIEW_3D'
bl_region_type = 'TOOLS'
bl_category = "Claas"

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

    obj = context.object
    mesh = obj.data

    row = layout.row()
    row.label(text="AutoEdgeBreak:")
    row = layout.row()
    row.prop(mesh, "use_auto_smooth", text="BreakEdge")
    row.active = mesh.use_auto_smooth and not mesh.has_custom_normals
    row.prop(mesh, "auto_smooth_angle", text="Angle")
    row = layout.row()
    row.label(text="ManualSmooth:")
    row = layout.row()
    row.operator("object.shade_smooth", text="Smooth", icon="SMOOTHCURVE")
    row.operator("object.shade_flat", text="Sharp", icon="LINCURVE")
    row = layout.row()
    row.prop(obj, "draw_type", text="Draw Type")
    row = layout.row()
    row.prop(obj, "show_wire", text="Wire")
    row.prop(obj, "show_transparent", text="Transparency")
    row.prop(obj, "show_x_ray", text="X-Ray")
    row = layout.row()
    #row.prop(mat, "alpha")
    split = layout.split()


But when I add the following value definition no buttons are drawn

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

    obj = context.object
    mesh = obj.data
    mat = context.material
    cmat = mat.cycles


What I try to do is to add an alpha value slider so I can set transparency for display and value in one area.

row.prop(mat, "alpha")
Yes, errors in the script's draw function will stop it from drawing beyond the line where the error happens (or it will stop drawing your panel entirely). The error you got is:

location: &lt;unknown location&gt;:-1
Traceback (most recent call last):
  File "/ui_panel.py", line ---, in draw
AttributeError: 'Context' object has no attribute 'material'


Fix this error and the panel will draw OK. It means context.material is the problem.

Get in the habit of starting Blender from Terminal during experimentation / development process. This will allow you to read the errors that occur when Blender doesn't explicitly tell you something's wrong.