Skip to content

Tips and Tricks #5 convert cmd line to GUI easily

I’m writing a series of irregular short posts on some tips and tricks on using Geospatial Python. They may not be best practice, but I hope they are of help. I’ll try and give some context to when I’ve used the ‘tip’.

Convert your command scripts to a GUI easily.

Frequently I’ve been asked ‘should we build a Graphical User Interface for the user(s) of the code that we have written?’. It is a tricky question loaded with many caveats, but more often than not I think the answer should be no. Building a great GUI takes alot of effort in planning and executing and after this… one slight change can mean support becomes very hard and in some cases you might have to start all over again.

Many of the clients I’ve worked with have small agile geo dev teams that are delivering phenomenal scripts/programs. In order to move onto the next thing they need to ‘make it useable’. This is not a small task at all and something that in consulting projects can be forgotten. Ideally code needs to be tested and versioned and handed over. At handover there needs to be a way a (non programmer perhaps) can run scripts with minimal intervention.  Often it is a straight decision between command line or GUI. And generally users prefer the later. The problem is this is significantly more effort.

I’d often recommend delivering code in command line form, giving the users clear documented options of the parameters (flags). With a bit of training/handover this is (for 90% of projects the best solution). However with Gooey you can very easily convert your command line work to ‘reasonable’ GUI’s.

Consider a simple command line input with the flag -n for name that gets printed back. The user needs to supply to run the code with the -n parameters supplied.

import argparse

def main():
   parser = argparse.ArgumentParser()
   parser.add_argument("-n", "--name", help="What is your name", action="store", required=True)
   args = parser.parse_args()

   print("you entered: ",

if __name__ == '__main__':

Then at the command line run

python -n Andrew

and it will print

you entered: Andrew

Now to turn this into a GUI just add the import statement and the @gooey wrapper on the main function and run


gives you

and when you press Start

The really nice thing is the ‘Edit’ and ‘Restart’ buttons. This is allows you to restart the code (with the same parameters) or edit the parameters and run again. This is incredibly useful! Your users will thank you for this way.

If you then get further requests for additional functionality you can further explore Gooey or make the decision to develop your own GUI whilst at the same time have a ‘working’ GUI while you add the necessary functionality.

I’ve found this to be so useful in my work, I hope you do to.

I’ve added comments where needed to the code here. I hope this has been of use.

I’ll be adding more tips and tricks

Links – Gooey –

And huge thanks to Chris who developed Gooey, check out his website here

Image credit

I am a freelancer able to help you with your projects. I offer consultancy, training and writing. I’d be delighted to hear from you.

Feel free to connect or follow me; I am always keen to talk about Earth Observation.

I am @map_andrew on twitter