There is a good overview in general of the link between Mercury and the CSD Python API within the Mercury documentation that you can access online here:
Mercury documentation (CSD Python API section)
I would probably suggest looking at one of the existing scripts that comes with Mercury though. The "chemical_name_search.py" which you can find under the CSD Python API > Searches menu contains a useful illustration of this type of interaction. That chemical name searching script uses a little Tkinter user prompt to gather input from the user. You can probably just cut-and-paste a section of the Python for your application.
Hope that helps!