how to refresh inventory display?

Hello

I have made a pickup system a time ago.
It works and all items are placed into global dict, and the inventory scene shows the items (plane with picture and amount number).

But when i open inventory and pickup an item it wont update(only does if i close inventory and open again).
I tried to set the script at True pulse, it kinda works but the numbers gets added why to much and it slows down the engine to like 10 fps.

is there a way to update somethin like that?

#edit
blend removed.

Send a message whenever the inventory is updated. For simplicity’s sake, wipe the inventory display when it is updated, and then recreate it


#################################################
#                                               #
#         inventory SCRIPT BY COTAX v0.1        #
#                                               #
#                 Blender v2.++                 #
#                                               #
#################################################
from bge import logic


# the amount when the inventory is full and only stackable items can be collected
max_slots   = 7
            
#how many items in a row (width)
slots_a_row = 4


#max items a stack allowed (only one stack of each item is allowed)
max_stack = 5


#spacing between the slots, no border = 1.0
border      = 1.02




def any_positive(cont):
    for sens in cont.sensors:
        if sens.positive:
            return True
    return False




def show(cont):
    if not any_positive(cont):
        return
        
    own = cont.owner
    scene = own.scene


    i               = 0    
    y_offset        = 0.0
    x_offset        = 0.0    
    
            
    inventory = logic.globalDict.setdefault("inventory", {})
    
    # Clear inventory display
    for child in own.children:
        child.endObject()
        
    for category in inventory:
        
        for item in inventory[category]:


            i += 1
        
            if i > slots_a_row:
           
                y_offset -= border
                x_offset = 0.0
                i = 1     
         
            inventory_item = scene.addObject(item, own, 0)                        
            inventory_item.worldPosition.y -= y_offset
            inventory_item.worldPosition.x -= x_offset
        
            text = scene.addObject('text_amount',own,0)
            text.worldPosition.y -= y_offset + 0.46
            text.worldPosition.x -= x_offset + 0.48
            
            amount          = inventory[category][item]        
            text['Text']    = amount
            
            text.setParent(inventory_item)
            inventory_item.setParent(own)


            x_offset += border 
            


def insert_items(cont):
    
    GD = logic.globalDict
    
    inventory = GD.setdefault("inventory", {})
    messages = GD.setdefault("messages", {})
    
    collision   = cont.sensors['Collision'].hitObject
  
    if collision:
        
        if collision is not None and collision['inventory'] == True:
        
            category   = collision['category']
            item       = collision['item']
            amount     = collision['amount']       
            
            slot_count = sum(len(obj) for obj in inventory.values())
            
       
            if not category in inventory:
                
                if slot_count < max_slots:
                    
                    if amount <= max_stack:
                    
                        inventory[category] = {item: amount}
                        collision.endObject()
                    
                        #message for hud
                        message['inventory_message'] = 'Picked up: '  + str(amount) + ' ' + item
                    
                    else:
                        
                        message['inventory_message'] = item + ' - Stack to large, not picked up!'                 
                        
                else:
                    
                    #message for hud
                    message['inventory_message'] = 'Inventory full'                 
                    
            elif not item in inventory[category]:
                
                if slot_count < max_slots:
                    
                    if amount <= max_stack:
                    
                        inventory[category][item] = amount 
                        collision.endObject()
                    
                        #message for hud
                        message['inventory_message'] = 'Picked up: '  + str(amount) + ' ' + item
                        
                    else:
                        
                        message['inventory_message'] = item + ' - Stack to large, not picked up!'
                 
                else:
                    
                    #message for hud
                    message['inventory_message'] = 'Inventory full'
                    
            else:
                
                stack_count = inventory[category][item] + amount
                
                if stack_count <= max_stack:
                    
                    inventory[category][item] += amount
                    collision.endObject()
                    
                    #message for hud
                    message['inventory_message'] = '+ ' + str(amount) + ' ' + item
                    
                else:
                    drop_count  = stack_count - max_stack
                    stack_space = amount - drop_count
                    
                    collision['amount']         = drop_count
                    inventory[category][item]   += stack_space
                                       
                    #message for hud
                    if stack_space != 0:
                        
                        message['inventory_message'] = '+ ' + str(stack_space) + ' ' + item
                        
                    else:
                        message['inventory_message'] = item + ' - Stack full!'


    logic.sendMessage("update_inventory")                        


       
def hud_info(cont): 
    
    GD = logic.globalDict
    
    if not 'messages' in GD:
        return


    own     = cont.owner
    scene   = logic.getCurrentScene()
    
    messages = GD['messages']
        
    if 'inventory_message' in messages:
        
        message = messages['inventory_message']
    
    if own['old_message'] != message:
            
        own['old_message'] = message


        text            = scene.addObject('inventory_info', own, 60)
        text['Text']    = message


        




            

Send a message whenever the inventory is updated. For simplicity’s sake, wipe the inventory display when it is updated, and then recreate it

You don’t want to know how long i tried to get this to work.
love the new GD style.

text.setParent(inventory_item) 
            inventory_item.setParent(own)

I didn’t think about to parent it to the spawner, that makes removing the objects way easier.

Thank you Agoose it works like a charm now.