Select to view content in your preferred language

Get user input text in arcpy

25734
27
Jump to solution
06-07-2012 11:12 AM
WilliamIde
Emerging Contributor
I want to ask the user what name to give to a report.  I could use Tkinter to do this but it seem there should be something in arcpy to do it.   Just pop up a little dialog ask for some text and return that text as a string.  Is there something like that?

Thanks.
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
NobbirAhmed
Esri Regular Contributor
Use raw_input to get user input in command line:

in_txt = raw_input('Enter your value :')

View solution in original post

27 Replies
JoelCalhoun
Deactivated User
You could easily do that in a script tool, but I'm not sure of your workflow.


Joel
0 Kudos
NobbirAhmed
Esri Regular Contributor
Use raw_input to get user input in command line:

in_txt = raw_input('Enter your value :')
WilliamIde
Emerging Contributor
To be clear.  I want a dialog by that pops up and asked the user to enter some text and press OK.   Then I return the the main program and use the text create a report heading.  raw_input gave me an error "EOF found while reading."
0 Kudos
JasonScheirer
Esri Alum
This isn't supported from ArcMap directly, the way for Python to interact with the user in the desktop environment is through GP tool dialogs. That is, write it as a script tool with the report name as a parameter.
NobbirAhmed
Esri Regular Contributor
If you really want a pop-up dialog you can create a script tool. For your convenience I'm attaching a python script tool as a zip file.

When unzipped, you'll see following files there:

PopUp.tbx - a toolbox containing a script too and a Model.
pop_up_script - the source script of the tool.
calling_script - how to call the tool from another stand-alone script.
python_window.txt - how to call the tool from Python window.

In ArcMap, browse to the location of the toolbox (unzipped folder). From the toolbox open the script tool - whatever text value you enter will be returned as a text. For this particular tool, it changes all character to upper case and returns it. If you need help - start here:

http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/A_quick_tour_of_creating_script_tools/...
lego8126
New Contributor

Dear NobiirAhmer

I m workin with arcgis 10.7. I am trying to use your application.

I run  arcpy.ImportToolbox(r"C:\0voltmp\PopUp.tbx") and works fine, the tool is imported but

when I run result = arcpy.PopupInputBox_popup("A message from popup box") no window pop up. Se picture below

can you help me. I dont kno why it not work. Thank you

Gabriel

lego8126_0-1645792447654.png

 

0 Kudos
WilliamIde
Emerging Contributor
I didn't get the zip file.
NobbirAhmed
Esri Regular Contributor
Sorry - here it is.
WilliamIde
Emerging Contributor
Ok I got the Zip file and am working with it.

I still can't get it to work.

In the code of calling_script.py  (I change to path to where I have it.)

You have:

try:
    arcpy.ImportToolbox(r"D:\Myprojects\Arcscripts\POPUP\PopUp.tbx")
    result = arcpy.PopupInputBox_popup("A message from Popupbox")

the "PopupInputBox_popup" is not resolved and the script won't run.  Also the test model has a Red "X" in it and won't run.

What now.

This is much harder that using Tkinter.
0 Kudos