Python Flask - 客户端的GUI [英] Python Flask - GUI for client

查看:641
本文介绍了Python Flask - 客户端的GUI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想运行一个客户端文件对话框GUI,以便用户可以选择一个文件来处理python()。

解决方案

不能将GUI小部件发送到浏览器,只能发送HTML,CSS和Javascript。请参阅烧瓶中的文件上传官方文档 http://flask.pocoo.org/docs/ 0.10 / patterns / fileuploads /

I want to run a client-side file dialog GUI so that the user can choose a file to process with python (example). My code, which fundamentally works fine, is here:

from flask import Flask, url_for, request
app = Flask(__name__)

@app.route('/data')
def gui_test():

    import Tkinter, tkFileDialog
    root = Tkinter.Tk()
    root.withdraw()
    filepath = tkFileDialog.askopenfilename()

    with open(filepath,'rb') as tt:
        lines = tt.readlines()

    return 'You are reading ' + filepath + '<p>Top 10 lines for proof of concept<p>'+'<br>'.join(lines[0:10])


if __name__ == '__main__':
    app.run()

Everything works fine, except that the GUI opens on the machine running this REST code, and not on in the client's user account.

The user should go with the browser to http://127.0.0.1:5000/data and then should see the file dialog:

Details: Windows Server 2012 R2, Flask 0.10.1, Python 2.7

If I'm taking the wrong approach, I'd appreciate suggestions for other directions. There may be something flawed in the idea, because of browsers not sharing the full path (javascript example).

解决方案

You can't send GUI widgets to browser, only HTML, CSS and Javascript. See official documentation for file uploads in flask http://flask.pocoo.org/docs/0.10/patterns/fileuploads/

这篇关于Python Flask - 客户端的GUI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆