I have a Flaks API with some endpoints. I use multiprocessing to run it parallel to my Program. Tkinter is started with window.mainloop()
.
I split all of them into their own classes (I don't know if this affects smth).
I now want to change the text of a label on my tkinter Label. I am using mylabel.config(text="myText")
and want to call this from my API Endpoint (A function like this:)
myEndpoint(self, newStatus:str):
self.mylabel.config(text=newStatus)
return newStatus
What can I do to change the Label when my Function is run by the API Process? Thanks for any help
EDIT: @Bryan Oakley wanted some more information. Here it is:
All functions for the Window are in their own class in another file. My Program imports it, create an Object with all needed parameters (Window Size and so on), and then starts it with:
from window import window
w = window(Parameters like Size, ...)
w.start()
Start function just changes the fullscreen Parameter and setup some Button actions. Then it calls self.window.mainloop()
window = Tk()
that is setup in my init
My Flask API has also its own class in another file and is imported:
from api import flaskApi
api = flaskApi(Port, window object, ...)
The init method of my api class setup Flask add the Endpoint with app.add_url_rule
to the function myEndpoint
(see above).
Hope this is all you need, I cant find a solution and are happy about your help. Thanks for any help :)
CodePudding user response:
After more and more research I finally found an Answer. To access another Process (here the main Process) from another one (here my Flask API) you need to use a Queue or Pipe (Queue Documentation).
This Queue (or Pipe) allows you to communicate with another Process. One reads from the Queue (here my Tkinter Window) and one (or more) write into it. Maybe this helps someone else with the same Problem.
Thanks for your help :)