How to display python application in html? How to display python application in html? tkinter tkinter

How to display python application in html?


You should check out mod_wsgi and one of the many web-packages in existence from the python community or build your own.

But you also need to understand that tkinter is a gui-library it will not run from the web, which it sounds like is what you want. But instead you could build a webinterface for your code, which shouldn't be to hard if the presentation logic is well separated from the application-logic. That being said it's definitely not an easy task if you're new to programming in general or web-programming in particular.


Take a look at Flask as a lightweight framework for making a web application and then have a route somewhat like:

@app.route("/graph/<input>")def drawGraph(input):    # Graph drawing code goes here.    image = # The image file as a string, as if you'd read it in from a file            # object    return Request(image, mimetype="image/png")

Then in the templates, you could use the /graph/ urls to fetch graphs for the appropriate input and render them in <img> tags.


If your interested in using the web-framework flask take a look at this, from this discussion on how to create a graph on-the-fly using matplotlib in flask.

I suggest storing the images somewhere like amazons s3 service.That way the images will be easy to access from session to session. So modifying the code from the thread link above...

return the objects as a png:

from matplotlib.pyplot import figurefrom matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvasimport StringIOdef create_a_graph()    fig = figure(figsize=a_size_integer,a_size_integer))    canvas = FigureCanvas(fig)    canvas.print_png(png_output)    return png_output

then upload them to amazons s3 site using boto and display them on what ever framework you choose.

A current project i'm working on does just this. Take a look at the files: graph.py, tools.py, views.py and base.html. Of course this requires understanding boto, flask and matplotlib but at least it gives you a starting place.