code: def start_sim(self, gui=True, set_values={}, error=None):
          
          self.error = error
          if not self.is_running.is_set():
              def loop():
                  self.need_to_stop.clear()
                  self.is_running.set()
                  for robot in self.robots:
                      if robot.brain:
                          self.runBrain(robot.brain)
                  count = 0
                  while not self.need_to_stop.isSet():
                      if not self.paused.is_set():
                          self.clock += self.sim_time
                          for robot in self.robots:
                              try:
                                  robot.update()
                              except Exception as exc:
                                  self.need_to_stop.set()
                                  if error:
                                      error.value = "Error: %s. Now stopping simulation." % str(exc)
                                  else:
                                      raise
                      if gui:
                          self.draw()
                      if count % self.gui_update == 0:
                          if "canvas" in set_values:
                              set_values["canvas"].value = str(self.render())
                          if "energy" in set_values:
                              if len(self.robots) > 0:
                                  set_values["energy"].value = str(self.robots[0].energy)
                      count += 1
                      self.realsleep(self.sim_time)
                      if self.robots[0].energy <= 0:
                          self.need_to_stop.set()
                  self.is_running.clear()
                  for robot in self.robots:
                      robot.stop()
              threading.Thread(target=loop).start()
docs: Run the simulation in the background, showing the GUI by default.