Replies: 2 comments 2 replies
-
The Flask server is blocking, so you must start it on a background thread if you want your UI to remain operational. To shutdown the server you have to send a request to it that calls the Werkzeug shutdown function. See the documentation to learn how to do this. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Also, on StackOverflow suggest using the following: from flask import request
def shutdown_server():
func = request.environ.get('werkzeug.server.shutdown')
if func is None:
raise RuntimeError('Not running with the Werkzeug Server')
func() And in your GUI you can add something like this: btn = tk.Button(main_window, text='stop flask server', command=shutdown_server) |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I would like to create a dialog box (tkinter) with an on/off button.
When the program starts, it starts the Flask server directly.
And with the button, you can stop or restart it.
But as soon as I run app.run, the dialog box does not work anymore.
I used parameter 'threaded=True', but not effect.
I tried with multithreading 'threading.Thread' to start flask and tkinter, it works. But in this case I can't stop the flask server on button click off.
Can anyone give me a hint?
Thanks
Environment:
Python version: 3.9.6
Flask version: 2.0.1
Tkinter : 8.6
Beta Was this translation helpful? Give feedback.
All reactions