I'm trying to use Flask to build the GUI for a desktop application (i.e. a web app running on a server running locally bundled with an embedded browser). Things mostly seem to work for now, but I'd like to add a file chooser to allow users to select a directory on their computer. I need the full path of the directory so opening a dialog using HTML/JavaScript won't work (because of security restrictions).
What I've tried doing instead is to launch a Tkinter file dialog when a button is pressed on the page. The problem is that while it does appear to launch something, the process just freezes (without displaying a window) and I'm forced to kill it, after which the page redirects to '/view_1_actions' and I get an "Error code: ERR_EMPTY_RESPONSE" error (i.e. the Flask app only crashes after I kill what appears to be the dialog window).
Here's my code:
HTML:
<form action="/view_1_actions" method="post">
<input type="submit" name="submit" value="Select"></input>
</form>
Python:
from flask import Flask, request, redirect
from Tkinter import Tk
from tkFileDialog import askdirectory
@app.route('/view_1_actions', methods = ['POST'])
def view_1_actions():
if request.form['submit'] == 'Select':
Tk().withdraw()
dirname = askdirectory()
return redirect('/')
Granted this a rather strange scenario since you wouldn't usually be launching a graphical interface on the "server side", but my question is whether there is a way to fix this or an alternative solution I could use to display a file chooser dialog (preferably the native one for each OS).