1

Python で書かれたプログラムがあり、このプログラムのパラメーター値を GUI から簡単に入力できるようにしたいと考えています。Pythonツールを使用してGUIを作成できることはわかっていますが、html/javascriptページの使用に興味があり、ユーザーがボタンをクリックして実行すると、javascriptコードがpythonスクリプトを呼び出すようにしています。何かのようなもの;

var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "../scripts/python_script.py", true);
xmlhttp.send();

現在、それを行うと、Pythonスクリプトのテキストが返されるだけですが、実際には実行されません。理想的には、Python スクリプトは Web ページへのそれ以上の入力をブロックすることなくバックグラウンドで実行され、スクリプトがさまざまな結果ファイル (png 画像) を生成すると、これらはブラウザーに表示されます。明らかに、私はこれを Web サーバーを使用して行うことができます (最終的にこれを行うことになる可能性があるため、html インターフェースを使用します)。そうすれば、html ページと python スクリプトを一緒にパッケージ化して、Web サーバーを起動することなく、自分のコンピューターでプログラムを実行できる人に渡すことができます。これは可能ですか?

そうでない場合、同様の結果を達成する別の方法はありますか? 起動時に HTML ページを表示し、XMLHttpRequest に応答して Python スクリプトを起動する Python スクリプトに小さなサーバーを埋め込むことはできますか? これを行った場合、ユーザーはスクリプトを開始してから、別のアクションとしてブラウザーで指定されたアドレスに移動する必要がありますか?

編集:SimpleHTTPServerを使用して簡単な解決策を見つけましたが、ボトルを見て、おそらくそれを使用して何かを試してみます. ご協力いただきありがとうございます。

4

2 に答える 2

0

First of all, using something like bottle it is pretty simple to make a web server to run your script. Look at http://bottlepy.org/docs/dev/

A good starting point is the code at http://bottlepy.org/docs/dev/tutorial.html#http-request-methods but you would put up a form asking for parameters rather than a login form. Then just run your Python script, capture the output and send it back in the return statement.

This question Capture subprocess output shows you two ways to run your main script depending on whether you want to show the output progressively or all at the end.

于 2011-10-13T07:40:29.100 に答える
0

You'd need to bundle some kind of webserver with the application. If it is not intended for deployment I would go for something like bottle.py. It's a micro web framework that has its own development server. Other micro/mini frameworks probably pack their own webserver with them for development purposes (web2py, flask, ..). If you want something more serious you'd probably need some better web server. If that's the case - have a look at this reddit discussion.

于 2011-10-13T07:41:17.693 に答える