SI_InteligentnyWozekWidlowy/visualization/DisplayPictureElement.py
Aleksander Szamałek 668ed6edf9 visual improvements
2022-05-25 23:52:03 +02:00

22 lines
631 B
Python

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 ""