0

I want to print information to a gui and am using a public framework so my choices are limited. I would like to update a function in this page so I can print to the gui. Using the python print() function sends the output to the command line so I cannot use it. The current framework uses a TextElement object that prints to the gui, however it prints a mass of text to the gui if I continue to add variables and starts to look sloppy:

def render(self, model):
    return ("Happy agents: " + str(model.happy)
    return ("# Agents in majority: %s \
            \n # Agents in minority: %s " 
     (model.countMajority, 
     model.countMinority ))

I added \n for line breaks but they are not adding new lines as I expected. I saw suggestions in stack overflow with tkinter but it is not a library in this framework. Do you have any suggestions how I can add a line break?

Thank you

BoarGules
  • 16,440
  • 2
  • 27
  • 44
ithoughtso
  • 103
  • 8
  • Treatment of line breaks in UIs is generally platform-dependent. – BoarGules Oct 31 '21 at 23:11
  • I thought new line \n would be standard in most languages ( I thought it would be a non issue). Is there an alternative to \n I can try? I am using a windows system and follow the instructions here: https://github.com/projectmesa/mesa/blob/main/examples/schelling/README.md – ithoughtso Oct 31 '21 at 23:31
  • 2
    This renders to a browser. You might try `return "# Agents in majority: %s
    # Agents in minority: %s" % (model.countMajority, model.countMinority)`
    – Tim Roberts Oct 31 '21 at 23:34
  • It's not the *language,* it's the *platform.* – BoarGules Oct 31 '21 at 23:35
  • Right. "\n" is a C invention, adopted by Python and Perl (and others), but it is certainly not universal. HTML does not use it. – Tim Roberts Oct 31 '21 at 23:38
  • Thank you Tim Roberts! A simple
    worked! That makes sense considering it is the interface but the code had no HTML formatting references, so I did not consider that option.
    – ithoughtso Oct 31 '21 at 23:56

0 Answers0