Next: Spawning external processes, Up: Python FAQ

##### 16.8.7.1 Hello World! in python

Writing a python script to interact with GPS is very simple. Here we show how to create a new menu in GPS that when clicked, diplays a dialog saying the famous “Hello World!”.

Here is the code that you need to put in hello_world.py:

         import GPS

         def hello_world (self):
            GPS.MDI.dialog ("Hello World!")

         GPS.Menu.create ("/Help/Hello World!", on_activate=hello_world)

In order to use this plug-in, you can launch GPS with the following command line:

         $ gps --load=python:hello_world.py

If would want the plug-in to be loaded everytime you launch GPS without having to specify it on the command line, you should copy hello_world.py to your `$HOME/.gps/plug-ins/` directory or `%USERPROFILE%\.gps\` under Windows.

Alternatively, you can add the directory in which you plug-in is located to you `GPS_CUSTOM_PATH` environment variable. For a description of the various environment variables used by GPS, see Environment Variables.