I'm working on text game project in Python. Currently i have finished console app + sqlite database. Now I want to convert console app to web app - it will be the first web app in my life.
I want to create a simple GUI. With main logo, background image, several buttons and text zones. Example of simple GUI project: simple gui project
I would like the logic of the application to be based on the code already created for console application. For example, by replacing the current console functions (for example print) with a function that returns data in the form of JSON. But without changing the internal logic of the function already written in Python. Is it possible? What is the easiest way (and what technologies?) to do that?
converting a python application to a web application is not a very practical task in some cases.
I think you should use something like Flask or Django but if you don't want to complicate your life too much, there may be an alternative, and it's called PyPy.js
The first things that you must take into account in the logic of web applications, is that HTML is the skeleton of what you are going to show, so you must study it, Javascript adds dynamism to your page, such as animations and data updates without reloading the page, and the CSS to add styles to your html tags.
<head>
<script src="http://pypyjs.org/pypyjs-release/lib/Promise.min.js"></script>
<script src="http://pypyjs.org/pypyjs-release/lib/FunctionPromise.js"></script>
<script src="http://pypyjs.org/pypyjs-release/lib/pypyjs.js"></script>
</head>
<body>
<script type="text/javascript">
pypyjs.exec(
// Run Python code
'y = "hellow" '
).then(function() {
// transferring the variables we need to Javascript, in this case only 'y'.
return pypyjs.get('y');
}).then(function(result) {
// Display an alert like print in Python
alert(result);
});
</script>
</body>
that would be the same as ...
y = "hellow"
print (y)