With Python Add-In Wizard I created a ButtonTool with which I:

  1. click in the map
  2. get the coordinates of the mouseclick-location in a dialog with textboxes

I want to receive the coordinates in a textbox to have the possibility to copy and paste the coordinate values (e.g. to use them in a document). I get a crash between TKinter and arcpy like I read in some posts before. Nevertheless I want to ask, if anybody has experience with this and has a suggestion.

Here is my code:

Import Tkinter
class ToolCoord(object):
    def __init__(self):
        self.enabled = True
        self.shape = "NONE" 
        self.cursor = 3
    def onMouseDownMap(self, x, y, button, shift):
           pt = arcpy.PointGeometry(arcpy.Point(x,y))
           main = Tkinter.Tk()
           lb = Tkinter.Label(main, text = "UTM-Koordinaten:")
           t1 = Tkinter.Text(main, width=20, height=0)
           t1.insert("end", str(x))
           t2 = Tkinter.Text(main, width=20, height=0)
           t2.insert("end", str(y))
  • 1
    Write to a temp text file and open it with notepad or write directly to the clipboard.
    – user2856
    Dec 18, 2015 at 20:30
  • @Luke: Thank you for the hint. That was a smart and simple solution. I made it with the Notepad. Feb 17, 2016 at 13:26

2 Answers 2


Tkinter and Esri Python Addins do not play nice together. You can use Tkinter within scripting with Acrpy, but it will usually crash when implemented in an Addin. wxPython GUIs will work within an ESRI Addin. However these will require the end user of your Addin to have wxPython installed on their machine.


Based on the hint of Luke I use now a eventbutton with the following code:

class ToolClass71(object):
    """Implementation for Python_Addins_addin.tool (Tool)"""
    def __init__(self):
        self.enabled = True
        self.shape = "NONE" # Can set to "Line", "Circle" or "Rectangle" for interactive shape drawing and to activate the onLine/Polygon/Circle event sinks.
        self.cursor = 3
    def onMouseDownMap(self, x, y, button, shift):
        pt = arcpy.PointGeometry(arcpy.Point(x,y))
        # set environment
        mxd = arcpy.mapping.MapDocument('current')
        mxdpath = mxd.filePath
        df = arcpy.mapping.ListDataFrames(mxd)[0]
        outWorkspace = os.path.dirname(mxdpath)
        # creating a temp feature in the memory space
        tempitem = arcpy.CreateFeatureclass_management("in_memory","item","POINT","","DISABLED","DISABLED","Arch_Denkmal_DSch")
        # add and populatin fields with coordinates
        fields = ["x_coords","y_coords"]  
        i = 0  
        for x in fields:  
            arcpy.AddField_management(tempitem, x, "DOUBLE")
            i = i + 1
        arcpy.da.InsertCursor(tempitem, ["SHAPE@XY"]).insertRow([pt])
        out_file = os.path.join(outWorkspace,"Koordinaten.txt")
        in_table = tempitem
        # export to csv
        # change rows and colums
        with open(out_file) as f:
            lis = [x.split() for x in f]
        with open(out_file, 'wb') as f:
          # Überschreiben der alten Datei mit den neuen Reihen
            writer = csv.writer(f)
            # csv öffnen
        subprocess.call(['C:/Windows/System32/notepad.exe', out_file])
        # delete temp objects and refresh active view

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.