How to refresh icon on UI when pressing button (maya)

So, i have a script I’m currently working on (cant talk much about it because of company policies). I hope you folks can help me out with this. I have created 3 icons in Photoshop for the script and once I run so called script, i see the right first icon shows on the UI, but once I click another button that’s supposed to change the image, to… say, “icon 2”, as you know it doesn’t update immediately. How can I approach an instant “update” of so called icon after the button press? If I close and re-run the script, the right icon shows, so it’s more about how to approach an instant update of it

def ON_icon(*args):
    ON_icon = cmds.internalVar(upd=True) + "icons/LayerTree/ON.png"
    cmds.image(w=25, h=25, image=ON_icon)

def OFF_icon(*args):
    OFF_icon = cmds.internalVar(upd=True) + "icons/LayerTree/OFF.png"
    cmds.image(w=25, h=25, image=OFF_icon)

def EMPTY_icon(*args):
     EMPTY_icon = cmds.internalVar(upd=True) + "icons/LayerTree/EMPTY.png"
     cmds.image(w=25, h=25, image=EMPTY_icon)

def base_layer_icon(*args):
    if (cmds.objExists('Base_layer')):
    elif not (cmds.objExists('Base_layer')):

This is just my foundation for this icon system, I’m just trying to find a way to do this. I read up on the “callback” way, but im still a bit confused on how to achieve it.

Have you tried running cmds.refresh() ? That tends to force Maya’s UI to be redrawn during script execution.

Hey, where should I place the cmds.refresh()? and should I use any attributes inside parenthesis?

You would want to run it after you change your image.
It doesn’t have any required arguments.

yeah its not working :frowning:

it’s not working if you add the force flag?

Solved it guys, had to rewritte it with an update_img def in order to keep updating it everytime i made a change depending on the button :slight_smile: