0

Wrote a tiny program which should start animating a graph if some specific message is send to an zmq socket. For zmq socket listening i use threads. If the specific message is received from within the thread it sends a virtual event to the root window. However the event is also triggered when binding to the root... how can this be? and how to solve it ...

Setting up a listener thread which sends a virtual event when received a command :

def commandReceiver():
      global commandAfterStart
      while True:
          commands = zmq_.recv_string()
          if 'START' in commands.upper():
              commandAfterStart = commands.replace("START ","")
              root.event_generate("<<Foo>>", when="tail")
              print ("Command received = "+commandAfterStart)
        
commandThread = threading.Thread(target=commandReceiver, args=(), daemon=True)
commandThread.start()

In the main thread

def doShow(*args):
        anim = FuncAnimation(fig, showGraph, 300)
        print("Animation started")
        return anim
            
root.bind("<<Foo>>", doShow())

However the event fires even on program startup... Anyone a clue how to fix this ?

HermDP
  • 205
  • 1
  • 6
  • It should be `root.bind("<>", doShow)` instead. Your code will execute `doShow()` immediately and use the result in `root.bind(...)`. – acw1668 Nov 26 '21 at 13:53
  • Thx! If I pass the function (like you suggested) instead of calling it, the event firing from the socket listening thread works... but the animation doesn't work anymore. I get an error : "UserWarning: Animation was deleted without rendering anything. This is most likely not intended. To prevent deletion, assign the Animation to a variable, e.g. `anim`, that exists until you have outputted the Animation using `plt.show()` or `anim.save()`. " even tough I'm assigning the result of the function to a variable so the result ain't garbage collected – HermDP Nov 26 '21 at 15:02

0 Answers0