0

I want to select a folder on a web flask server. I've tried referring to Python-flask-gui replacing with the current py3 syntax (below), tkinter works fine standalone but freezes trying to open a window when used with flask.

I believe it could be the exact same issue as flask-desktop-application-file-chooser, but I am unsure how to approach

"What I would recommend would be to have the flask view function start/message a separate thread and then return immediately. (With whatever background you want behind the dialog.) The other thread is responsible for doing the dialog window in a native OS fashion, then when the user selects something and it finishes, send another flask request internally that will do whatever it needs to do with the selected file."

My code looks like:

@app.route('/sync', methods=['GET', 'POST'])
def sync():
    form = syncForm()
    from werkzeug.utils import secure_filename
    from tkinter import filedialog
    import tkinter as tk
    if request.form.get('file_chooser'):
    #if 'choose folder' button is selected
        import tkinter
        from tkinter import filedialog
        root = tkinter.Tk()
        #(crashes here)
        root.withdraw()
        filepath = filedialog.askdirectory()

return render_template('sync.html', title='Sync', form=form)

stacktrace starts with

2017-09-28 01:57:54.365 Python[69815:1489923] -[NSView 
_registerWithBackdropView] should not be called off of the main thread. 
Invocation was here:(0   AppKit...     

This is the same stacktrace that I get when I create a class in my forms.py and call it from there.

Thanks for the help!

gary
  • 223
  • 1
  • 2
  • 8

0 Answers0