Search code examples
pythonwxpython

Converting existing command-line script to GUI in python


This might seem as silly question but I am thinking there might be the simple solution for this problem. I have a python script which does some mathematical calculation which is command-line-based. I don't want to make any major modification to the code which I have right now. What should be my approach now to create a GUI ( I use wxpython) which uses that script as its model while leaving model to function as stand-alone python script as it is right now. I know it is the question of inheritance and polymorphism but I am not clear about the approach I should take. Any guidelines will be greatly appreciated.


Solution

  • It depends on the quality of your command line tool. Basically if it is written "correctly", it encapsulates its functionality in some functions or classes which are reusable in other scripts - meaning you can import and use them without problem. The "main" portion of the command line tool then parses command line arguments and calls those functions / classes. It that all is true then you can, obviously, import your functionality in GUI based app and use it.

    So in short your functionality has to be separated from user interface and then switching the interface is more or less trivial. This is usually called separating front end and back end.