Get user input text in arcpy

23947
27
Jump to solution
06-07-2012 11:12 AM
WilliamIde
New Contributor II
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
27 Replies
NobbirAhmed
Esri Regular Contributor
Once you get used to it you'll love script tools 🙂

In Catalog tree, right-click on the script tool and select Properties...

Click on the second tab Source and check whether the path to the script is where you have saved your script:

[ATTACH=CONFIG]15181[/ATTACH]

If you still get error please email me at nahmed@esri.com - we'll post the result to the thread once solved.
0 Kudos
WilliamIde
New Contributor II
Nope All I get back is "A Message from popup box"  Which is the string going in. Nothing ever pops up.  I runs completes ARRRR...  I am done with the writing the code in Tkinter. took me about 10 min.  I run all the arcpy I need to get the job done.  Why isn't Tkinter supported?  I think it should be.
0 Kudos
NobbirAhmed
Esri Regular Contributor
All I get back is "A Message from popup box"  Which is the string going in. Nothing ever pops up.


Nothing will pop up - the tool that you are using is the dialog and substitutes the pop-up. You use it to get a string value from the user. So, in your case, the user will type the name of the report (a string), the script behind the code will capture the string and do whatever you want the script to do. The advantage is that you can chain this dialog (i.e., the tool) in ModelBuilder and any other Python or .Net or Java application. You can drag-drop this tool to an ArcMap toolbar - it will work as a button.

Why isn't Tkinter supported?  I think it should be.  


The reason is TkInter's event loop does not work with ArcMap.

You can read through these forum threads where some users are able to use TkInter.

http://forums.arcgis.com/threads/38292-Making-a-GUI-app?highlight=TkInter

http://forums.arcgis.com/threads/58207-ArcPy-and-Tkinter?highlight=TkInter

http://forums.arcgis.com/threads/32040-Tkinter-GUI-Disconnect-with-ArcGIS-Script-Interface?highlight...
0 Kudos
WilliamIde
New Contributor II
In future releases of Arc 10.x.  It seems to me that ESRI could find out where the conflict is with Tkinter and  fix it.  ESRI seem to be using  Python as the main scripting language.  Which I think is a good idea.  But, if they are, they should adopt it fully and not just the scripting part.  That way we developers could bring the whole weight of the Vast python set of tool to bear on any problem we find.
0 Kudos
JeffButurff
New Contributor
I'm stuck on this same concept.  Any resolution here? 

All I want to do is be able to provide a text input box to the user.  For example, I want the user to "Enter a PIN:".  When they do, I search for that pin.  Zoom to the selected feature.  Buffer it by 100'.  Select all the features in the buffer.  Create mailing labels of all the features.

Everything else is easy enough to do with a Python add-in, except Step 1:   ASK THE USER FOR INPUT....
0 Kudos
NobbirAhmed
Esri Regular Contributor
Use a combobox to take the input. Make sure set the combobox's editable property to true.

Write your code inside the OnEnter event of the combobox.
0 Kudos
JeffButurff
New Contributor
Is there no easy way to present a modal dialog box asking the user for input when they hit a button using a python add-in?  This was basic functionality in VBA in ArcGIS 8.0. 

My client has a custom toolbar with 10 buttons on it, each representing a different type of "search".  When the user clicks a button, it presents a modal dialog box, asking for the "search item", such as PIN, ADDRESS, POLE_ID, etc. 

My client would prefer this all be written in python for maintenance reasons, but it sounds like Python can't do this simple task...
0 Kudos
NobbirAhmed
Esri Regular Contributor
Sorry Jeff 😞 There is no TextBox add-in even in ArcObjects .Net SDK.

These controls are created through an IDE. You can use WxPython to create such controls. Here is a blog - check it out:

Custom wxPython GUI�??s: an approach for ArcGIS 10.1

The easy and safe is to create a script tool (with a string parameter in your case) and call pythonaddins.GPToolDialog(.....) to pop-up that tool.
0 Kudos
PatrickJurgens
New Contributor III
Use a combobox to take the input. Make sure set the combobox's editable property to true.

Write your code inside the OnEnter event of the combobox.


The problem with this is that I want to accept a long string from the user, maybe one thousand characters. I can't expect them to enter that in a tiny combo box, and it would be especially lame to make a very large combo box that would use up valuable screen space even when it is not in use.
A popup window with a text box is what I want. Not a combo box, not a stupid script tool interface.

The TKinter internal loop back problem has been know about for a long time. Why not fix it already?

also, wxPython is not a python standard library. At my work place I am unable to install python libraries, so I am stuck with tkinter.
0 Kudos
stevekenneth
New Contributor II

Hi. Thanks to Mr Nobbir for the zipped file. I'm searching for something like that more than a year

I would create an customized tool for cadastral search. I would to know how set this script to search a value in shapefile table, to return a message if the inputs value hasn't been found, or automaticaly sélect thé feature if the user inputs exist.

Thanks before

0 Kudos