To prepare your script for receiving a parameter from the user, assign
arcpy.getParameterAsText(0). The zero in the assignment identifies this as the first parameter you will set in the script tool.
Next, modify your script to work with the parameter. Add an IF/ELSE statement to handle the option to clear the query:
value = arcpy.getParameterAsText(0)
if value == 'NONE':
queryStr = ''
queryStr = str(queryField) + "=" + str(value)
Your existing FOR loop should then function as expected and set the query.
Once these changes are made in the script, you'll need to configure the script tool in ArcMap. If you are sure that the values in the field you plan to query are not going to change, you can set them manually when editing the script tool. Right-click the tool and select Properties, then choose the Parameters tab.
- Add a suitable Display Name for the parameter and set the Data Type to 'String'.
- Under Parameter Properties, set the Filter to 'Value List'.
- Click the ellipsis next to the Filter, and in the resulting Value List box, enter the possible query values, making sure to include the option for NONE as well as to match the case for the values as they appear in the attribute table (I make mine all caps for ease).
Once this is done, you should be able to run the script tool and select the required value to set the query, or select NONE to have the definition query cleared.
If you want to take the tool a step further, you can add tool validation to obtain the values for the filter from the relevant field on one of your layers. The image below shows how this can be done. I've posted it as an image rather than a code block so that I can highlight the line numbers which contain changes from the standard tool validation. If you do choose to use tool validation, you'll need to insert the NONE option to the list being built since it doesn't appear in the field being used to populate the filter list - this is line 17 below, and the value is underlined in red .