Issue
I am developing a customtkinter GUI that lets the user view a set of crosswords data categories I have made, then load that crossword with an amount of words that the user specifies. When the crossword is generated, I run a flask web app with some parameters and I use Jinja2 templating to visualise the crossword and its clues (I was going to use tkinter but it sucks at making large grids).
Here is some sample code:
import cword_webapp.app as app
crossword = Crossword(params...)
app.start_app(word_count=crossword.word_count, ) # and so on
The cword_webapp.app code:
from flask import Flask, render_template
app = Flask(__name__)
def start_app(**params):
@app.route("/")
def main():
return render_template(
"index.html",
word_count=params["word_count"],
... # and so on with the crossword data
app.run(debug=True)
Doing it like this stuffs the tkinter GUI up and I lack the experience to know how to do it properly.
Anyone know how to launch the web app properly? (perhaps there is a way to also retrieve what ip and port it is hosted on and display it to the user as a link within a tkinter messagebox). Also, is there a way to detect when the app is closed and reflect that change in the GUI? Remember that this will be locally hosted and is only meant so that the user can interact with a generated crossword.
EDIT: Should've been more specific as to how it stuffs up – a new instance of the gui is created, and the flask server stops working
Solution
Running the Flask app is blocking Tkinter from updating. If you must use tk it might be best to write the whole app in it, and not involve flask.
If you want to use both, you could run them as two separate processes using the subprocess module.
Alternatively, you could multi-thread it, but if this is for a school assignment, I wouldn't recommend it
Answered By - doougal
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.