SI_InteligentnyWozekWidlowy/visualization/DisplayPictureElement.py

22 lines
631 B
Python
Raw Normal View History

2022-05-25 23:51:29 +02:00
from mesa.visualization.modules import TextElement
class DisplayPictureElement(TextElement):
def __init__(self, attr_name):
'''
Create a new text attribute element.
Args:
attr_name: The name of the attribute to extract from the model.
Example return: "happy: 10"
'''
self.attr_name = attr_name
def render(self, model):
val = getattr(model, self.attr_name)
if val is not None:
return self.attr_name + ': <img src="{}" alt="{}" style="width:148px; hei ght:148px;" >'.format(val, self.attr_name)
else:
return ""