1
$\begingroup$

I want to show an Image in my UI

enter image description here

I found the same question here but It didn't work for me

I haven't any error but It didn't show an Image in UI

import bpy
 
 
class ADDONNAME_PT_main_panel(bpy.types.Panel):
    bl_label = "Main Panel"
    bl_idname = "ADDONNAME_PT_main_panel"
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'UI'
    bl_category = "New Tab"
 
    def draw(self, context):
        layout = self.layout
        scene = context.scene
 
        obj = context.object
        

        row = layout.row()
        image = bpy.data.images.load("C:/Users/Kamali/Desktop/Test.png")

        row.template_ID_preview(image, "image", open="image.open")
        row.operator("addonname.myop_operator")
        row = layout.row()
        

            
            
 
 
class ADDONNAME_OT_my_op(bpy.types.Operator):
    bl_label = "Operator"
    bl_idname = "addonname.myop_operator"
    
    
    def execute(self, context):
        scene = context.scene
        return {'FINISHED'}
    
          
classes = [ADDONNAME_PT_main_panel, ADDONNAME_OT_my_op]
 
 
def register():
    for cls in classes:
        bpy.utils.register_class(cls) 
       
 
def unregister():
    for cls in classes:
        bpy.utils.unregister_class(cls)
        del bpy.types.Scene.my_tool

 
if __name__ == "__main__":
    register()

but I can't see any texture in my panel?

enter image description here

I'm sure that my image loaded correctly

enter image description here

$\endgroup$
9
  • 1
    $\begingroup$ There are several ways of displaying an image, Another way: row.template_ID_preview(data, "image", open="image.open"). Please be more specific what exactly does not work. $\endgroup$
    – brockmann
    Aug 30, 2020 at 8:46
  • $\begingroup$ @brockmann your solution didn't work for me: row.template_ID_preview(bpy.data, "image", open = "C:/Users/Kamali/Desktop/Test.png") $\endgroup$ Aug 30, 2020 at 9:06
  • 1
    $\begingroup$ How to use it: docs.blender.org/api/current/… $\endgroup$
    – brockmann
    Aug 30, 2020 at 9:10
  • 2
    $\begingroup$ Surely trying to load an image in a draw method is spitting errors constantly to console? Recommend double checking before chirping "it doesn't work" The open argument is an operator not a filepath. bpy.data has no property "image" $\endgroup$
    – batFINGER
    Aug 30, 2020 at 12:19
  • 1
    $\begingroup$ There are errors. ui_template_id: pointer property not found: Image.image The object is an image which has no property "image" hence the error. Are you aware of how getattr(foo, "bar") works. Also See blender.stackexchange.com/questions/6173/… Finally loading an image in a draw method is not a good idea, this is why your "loaded image" image above is number 67... and counting. $\endgroup$
    – batFINGER
    Aug 30, 2020 at 17:38

0

Browse other questions tagged .