I want to make an image display in UI panel so I find this how to display an image in blender UI with python? but when I run script of this which provided in how to display an image in blender UI with python?
import os
import bpy
import bpy.utils.previews
directory = os.path.join(bpy.utils.user_resource('SCRIPTS'), "presets", "scatter_presets_custom\\")
list_raw = []
from os import listdir
from os.path import isfile, join
onlyfiles = [f for f in listdir(directory) if isfile(join(directory, f))]
for f in onlyfiles:
if f[-4:] == ".jpg":
list_raw.append(f)
class Panel(bpy.types.Panel):
"""Creates a Panel in the 3D view Tools panel"""
bl_idname = "TEST_PT_Panel"
bl_label = "Scatter Icon test"
bl_category = "Scatter BETA"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_context = "objectmode"
def draw(self, context):
global custom_icons
for z in list_raw:
self.layout.template_icon(icon_value=custom_icons[z[:-4]].icon_id,scale=10)
# global variable to store icons in
custom_icons = None
def register():
global custom_icons
custom_icons = bpy.utils.previews.new()
for z in list_raw:
custom_icons.load(z[:-4], os.path.join(directory, z), 'IMAGE')
bpy.utils.register_class(Panel)
def unregister():
global custom_icons
bpy.utils.previews.remove(custom_icons)
bpy.utils.unregister_class(Panel)
if __name__ == "__main__":
register()
Blender showed this error Python script failed, check the message in the system console see the photo below

So I go and check toggle system console and it showed this. I don't know what is the problem.

I have a question on how to display an image in blender UI with python? Where can I paste the file location of my image? Can anyone tell me in where can I paste my file location of that photos or the script can find the path itself?
2nd question: Can I connect this script to the path which I searched in add-on preference

