Python Desktop Application with the Browser as an interface?

25,534

Solution 1

Python offers two things that should be of your interest:

  • a web server in the standard library
  • a standartized interface for web applications, called WSGI

So it is relatively easy to add a web interface to your application. For example in Mercurial (the versioning system), you have a command hg serve that launches a web server.

To see python launching a web server, and a WSGI app, just do:

python -m 'wsgiref.simple_server'

You can look at the wsgiref source code or some WSGI tutorial to do a simple app.

After that, you may want to use a web framework (for templating & co), but that is another question...

Solution 2

You could use Pyjamas. It's a port of Google Web Toolkit to Python, which basically means you write in Python and it gets compiled to HTML and JS.

Solution 3

There are plenty of excellent GUI tools for the way you want to do your GUI -- HTML, CSS, and Javascript. If you don't know of any, ask in a separate question with the right tags.

The Python side in such an arrangement should have no GUI of its own, but just run a subclass of the Python's standard library's HTTP server, just serving the HTML, CSS, and JS files, and data via JSON on other URLs that the JS can reach with Ajax techniques, essentially implementing storage and business logi -- so it's far from obvious what "GUI tool" you could possibly want for it?!

Just develop the Python side on its own (e.g. with IDLE, Wingware, SPE, or whatever you like) and the HTML / CSS / Javascript separately, with its own "GUI tool". All that Python will do with those files is statically serve them, after all.

You could be thinking of using some Python side templating, such as Mojo &c, but my recommendation is to avoid that: rather, go with the "thin server architecture" all the way, make the Python side a RESTful server of business logic and storage layers, and do all the GUI work in the browser instead.

Share:
25,534

Related videos on Youtube

Eli
Author by

Eli

Updated on July 09, 2022

Comments

  • Eli
    Eli almost 2 years

    I want to create an application that runs on the users computer, a stand-alone application, with installation and what-not, but I want the interface to be a browser, either internal and displayed as an OS window or external accessible using the browser (i.e. some http server).

    The reason would be because I know a little about Python, but I think I can manage as long as I have some basic roots that I can use and manipulate, and those would be HTML, CSS, and Javascript.

    I've yet to find a good GUI tool which I can use, and always abandon the idea after trying to mess around and eventually not getting anything.

  • Ignacio Vazquez-Abrams
    Ignacio Vazquez-Abrams about 14 years
    Except it isn't, since its latest commit was only a couple of weeks ago.
  • Max Shawabkeh
    Max Shawabkeh about 14 years
    This is one way, but other languages (e.g. .NET ones) have libraries that allow easy embedding of a browser into a window and scripting it or communicating via a simple API. I've found that useful on several occasions myself, but have been unable to find an equivalent in Python. wxPython has a browser widget, but it's quite outdated and doesn't even support scripting IIRC. Tk has nothing. There's a Webkit embedding for one of the GUI toolkits, but it's a severe pain in the behind to compile and integrate.
  • Eli
    Eli about 14 years
    I think I'm looking for what Max is talking about, an embedded browser that can communicate directly via JS API with the desktop application.
  • Eli
    Eli about 14 years
    Yes and no. I do have a problem with the GUI toolkits, and for me, as a web developer, it's much easier to get going with standard HTML and JavaScript. Isn't Qt only works for non-commercial applications if I don't have Qt license?
  • Admin
    Admin about 14 years
    @Eli, Qt has a dual LGPL/Commercial license. Basically, if you plan on publishing your application, you either need to open source it, or get a commercial license.
  • Kevin Whitefoot
    Kevin Whitefoot over 9 years
    For completeness it should be mentioned that running the backend as a localhost wsgiref http server means that it is available to any user who is logged in to the machine not just the user who launches the server. If you are the only user it's not a problem of course; perhaps it could even be regarded as a feature if there are multiple users.