grbll
grbll

Reputation: 141

How to equip python app with an arbitrary interface?

I am writing a small python app (a board game), currently I am writing the actual game with its logic.
Later on, I want to add a graphical Interface maybe with python, maybe in a different language, maybe as a web application, also a multiplayer option, maybe I'll host a server...

Is there a way to give my app an interface, so any of these possible extensions, are able to access the game, even if they are written in another language, run on another machine? I would like to add this interface once, so I don't have to change the entire base code for everything else I add.

So far I think I am looking for an API. However, every example I can find is about retriving and storing data from some database between a client and a remote server. Whereas, I will store all the data (for one session of the game) in the game's objects (its a boardgame, so it maybe 100 objects) and if I only add a GUI the communication I am looking for will happen between processes on the same machine.

Should I use something else (for example, I saw that I can define entry points when installing a python application via setuptools). Or, should I still use an API? If so, what protocol do you reccomend? Where should I start to learn?

Upvotes: 0

Views: 70

Answers (2)

Albert Shown
Albert Shown

Reputation: 259

If you have HTML/CSS/JS skills, you can use a web technologies UI library like WebView in Python, or WebUI using Python.

Source: https://github.com/alifcommunity/webui/tree/main/examples/Python/hello_world

Docs: https://webui.me/docs/#/python_api

You can create the UI you want, receive commands/clicks, and send/update the UI as you need quickly.

Upvotes: 0

Radosław Szumiwąs
Radosław Szumiwąs

Reputation: 140

For general communication (in future maybe over internet), you can use python socket.

For the time being, you open a port on localhost and handle incoming commands accordingly.

Here's a link to help you get started with sockets

Upvotes: 0

Related Questions