0

I've built a very simple assistant app in python which can do very basic tasks like taking notes, reminding you, stopwatch, timer, web scrape for news feeds etc. tkinter seems confusing and looks oldish to me. On the other hand, css js seems much easier to design gui side and way more elegant looking. Is it possible to design a desktop gui app (may be with electron?) using HTML+CSS+JavaScript but it will run my old python codes?

I've been coding for only two months and i suck at it. Please excuse my newbiness.

TLDR: Simply, i want to make the gui side using HTML+CSS+JavaScript to take user input but then it will run python scripts and shows output in the gui app. Is it possible?

3 Answers3

0

It can't be done, you'd have to make it like a web app (although with local webserver serving python responses)

EDIT: if you don't mind running it in webbrowser, you can make quite easily webserver, that will evaluate your queries...

MacHala
  • 2,159
  • 1
  • 15
  • 18
  • I don't understand your answer. You say it can't be done, then suggest a way that it can. I think your answer would be better if you remove the first four words – Bryan Oakley Sep 01 '17 at 18:39
  • it can't be done as desktop application (that's what I think he meant by "gui app") - I suggested workaround – MacHala Sep 01 '17 at 19:14
  • Even then, it can be done. A desktop application is just an icon that you double-click on. There's no reason why that application can't be a webserver with a bunch of embedded data for the UI. – Bryan Oakley Sep 01 '17 at 19:23
  • well, I guess we just don't agree about definition of desktop application – MacHala Sep 01 '17 at 19:28
0

The popular form of Javascript or ES6 (which you are talking about) is designed to run in browser, so, the limitations are that it can only make calls via browser, i.e. it cannot directly interact with the OS like python's OS module. This means you will need a web-service in your computer that would run a specific python code and return you the responses, this requires a web-service/web-framework, preferably python's like Django, Flask which will run the python script for you because they can make OS calls on the server machine. I do think other non-python web-services are cacpable to do so, but of course, the natural preference would be 'Python-based services'.

Sidenote: If the case was with Node.js(i.e. the server-side js) and not ES6(client-side browser-run) you would have an upperhand i.e. you could invoke python scripts on your server because node.js like the python-based web-servers do support os calls.

officialaimm
  • 378
  • 4
  • 16
-1

Kinda, but its real ugly. If you can host your data and whatnot the other approaches will work.

You have to build your project around nw.js. Essentially it is a Chromium build that adds local file system access back in. You can build an HTML+JS Front end and access a node.js backend running in the same thread. Via node you can shellout to call your python program, or run a local python web server.

I built a mapping app that allowed the user to select a local file, process it on the local machine with python and display the results in an interactive D3 app with geojson based layers of the UnitedStates. Since the data was proprietary I could not host it outside the company. Since I was not IT, I could not host it inside the company. nw.js allowed me to package everything into an installer and deploy to other people within the company as a standalone app.

See here for more information:

Official site: http://nwjs.io

Official documentation: http://docs.nwjs.io/

Introduction

NW.js is an app runtime based on Chromium and node.js. You can write native apps in HTML and JavaScript with NW.js. It also lets you call Node.js modules directly from the DOM and enables a new way of writing native applications with all Web technologies.

It was created in the Intel Open Source Technology Center.

Features

  • Apps written in modern HTML5, CSS3, JS and WebGL.
  • Complete supportfor Node.js APIs and all its third party modules.
  • Good performance: Node and WebKit run in the same thread: Function calls are made straightforward; objects are in the same heap and can just reference each other;
  • Easy to package and distribute apps. Available on Linux, Mac OS X and Windows
WombatPM
  • 2,561
  • 2
  • 22
  • 22
  • I think saying "you **have** to build your product around nw.js" is too strong. There are many ways to do what the OP is asking. – Bryan Oakley Aug 31 '17 at 21:35
  • And those approaches are what? Because I'd love an easier way to use JS + html as the UI for a desktop app. – WombatPM Sep 01 '17 at 14:32
  • You could create a traditional web app, zip it up into an executable python package. and then use a normal browser for the UI. Then there's also electron. – Bryan Oakley Sep 01 '17 at 14:42
  • Except if you want the web app to have access to the local file system, a regular browser is a no go. Like I said, if you can host everything great. The description made it seem like more local access was required. I have not looked at electron recently, so that may be a better approach. – WombatPM Sep 01 '17 at 18:02
  • _"Except if you want the web app to have access to the local file system, a regular browser is a no go"_ - that's not true. The server has access to the local file system. I'm talking about a lightweight server running on your desktop. It has access to everything. – Bryan Oakley Sep 01 '17 at 18:36