<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Draw a rectangle by dragging in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/draw-a-rectangle-by-dragging/m-p/274812#M21229</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Dear Kimo&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You don't know how much your help is valuable for me. Thank you. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My question&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Can I use the last codes you gave me as a solution in my Tkinter because I definitely need a Tkinter widget GUI in my project? &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you for your help. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Best Regards &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Babak&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 02 Feb 2013 02:47:00 GMT</pubDate>
    <dc:creator>babakkasraei</dc:creator>
    <dc:date>2013-02-02T02:47:00Z</dc:date>
    <item>
      <title>Draw a rectangle by dragging</title>
      <link>https://community.esri.com/t5/python-questions/draw-a-rectangle-by-dragging/m-p/274807#M21224</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Experts&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;How can I draw a rectangle on my map by clicking and dragging my cursor click using python codes?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Best Regards &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Babak&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Jan 2013 21:17:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/draw-a-rectangle-by-dragging/m-p/274807#M21224</guid>
      <dc:creator>babakkasraei</dc:creator>
      <dc:date>2013-01-25T21:17:47Z</dc:date>
    </item>
    <item>
      <title>Re: Draw a rectangle by dragging</title>
      <link>https://community.esri.com/t5/python-questions/draw-a-rectangle-by-dragging/m-p/274808#M21225</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;At the start of a script you can use the FeatureSet input type in a dialog.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;You need to have a template featureclass to refer to, in this case a polygon, as a layer to define the symbol to draw.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Then when you run the tool you can interactively draw one or more polygons or rectangles just like using the draw tools.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In the script you can pick up the geometry object if it was the first parameter and use it &lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
inRecSet = arcpy.GetParameter(0)&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;This has been available since 9.3&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You would have to run the tool again to repeat.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you want more control then 10.1 AddIns will give you access to the message queue of mouse clicks, and tracking.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;But AddIns are significantly more trouble, so try the featureset first.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 13:24:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/draw-a-rectangle-by-dragging/m-p/274808#M21225</guid>
      <dc:creator>KimOllivier</dc:creator>
      <dc:date>2021-12-11T13:24:09Z</dc:date>
    </item>
    <item>
      <title>Re: Draw a rectangle by dragging</title>
      <link>https://community.esri.com/t5/python-questions/draw-a-rectangle-by-dragging/m-p/274809#M21226</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you Kim for your answer. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Best regards &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Babak&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Jan 2013 14:47:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/draw-a-rectangle-by-dragging/m-p/274809#M21226</guid>
      <dc:creator>babakkasraei</dc:creator>
      <dc:date>2013-01-28T14:47:46Z</dc:date>
    </item>
    <item>
      <title>Re: Draw a rectangle by dragging</title>
      <link>https://community.esri.com/t5/python-questions/draw-a-rectangle-by-dragging/m-p/274810#M21227</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;At the start of a script you can use the FeatureSet input type in a dialog.&lt;BR /&gt;You need to have a template featureclass to refer to, in this case a polygon, as a layer to define the symbol to draw.&lt;BR /&gt;&lt;BR /&gt;Then when you run the tool you can interactively draw one or more polygons or rectangles just like using the draw tools.&lt;BR /&gt;&lt;BR /&gt;In the script you can pick up the geometry object if it was the first parameter and use it &lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
inRecSet = arcpy.GetParameter(0)&lt;/PRE&gt;&lt;BR /&gt;This has been available since 9.3&lt;BR /&gt;&lt;BR /&gt;You would have to run the tool again to repeat.&lt;BR /&gt;&lt;BR /&gt;If you want more control then 10.1 AddIns will give you access to the message queue of mouse clicks, and tracking.&lt;BR /&gt;But AddIns are significantly more trouble, so try the featureset first.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Dear Kim&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Your guide is really important. However, I really don't know how to apply it into my codes. I have created codes for my first button in my Tkinter that some parts of it are created with your help. I really thank you.&amp;nbsp; Following you can see my codes. they don't work, I really appreciate it if you please help me to correct them to be able to be used as a tool to work like select by rectangle tool. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;


def button1Click(self, selection):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; def __init__(self):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.enabled = True
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.cursor = 1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.shape = 'Rectangle'

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; def onRectangle(self, rectangle_geometry):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #"""Occurs when the rectangle is drawn and the mouse button is released.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #The rectangle is a extent object."""
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Extent of the feature

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; extent = rectangle_geometry
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd=arcpy.mapping.MapDocument("CURRENT")

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Set the workspace
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; env.workspace = mxd
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; index = self.listbox.curselection()&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; label = self.listbox.get(index) 

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Local variables:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; layer = label

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; df = arcpy.mapping.ListDataFrames(mxd)[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Create a search cursor from layer
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sCur = arcpy.SearchCursor(layer, '"CNTY_NAME" = \'Orange\'')
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Fetch each feature from the cursor and examine the extent properties
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in sCur:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; geom = row.shape
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ext = geom.extent # or row.Shape.extent
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Create an Array object.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #The DataFrame extent object is converted into a polygon feature so it can be used with the SelectLayerByLocation function.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dfAsFeature = arcpy.Polygon(arcpy.Array([df.ext.lowerLeft, df.ext.lowerRight, df.ext.upperRight,&amp;nbsp; df.ext.upperLeft]),df.spatialReference)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByLocation_management(layer, "INTERSECT", dfAsFeature, "", "NEW_SELECTION")

&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I hope you help me.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Best regards &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Babak&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 13:24:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/draw-a-rectangle-by-dragging/m-p/274810#M21227</guid>
      <dc:creator>babakkasraei</dc:creator>
      <dc:date>2021-12-11T13:24:11Z</dc:date>
    </item>
    <item>
      <title>Re: Draw a rectangle by dragging</title>
      <link>https://community.esri.com/t5/python-questions/draw-a-rectangle-by-dragging/m-p/274811#M21228</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;The featureset is part of the ArcGIS toolbox parameters. It does not use TKinter at all.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Your code attempts to use objects only available using a full AddIn. &lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#//014p0000001q000000" rel="nofollow noopener noreferrer" target="_blank"&gt;http://resources.arcgis.com/en/help/main/10.1/index.html#//014p0000001q000000&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You can use Tkinter to draw rectangles on a Tkinter window, but not the ArcMap window, so the coordinates will not be transformed to map units. The message queues between ArcGIS and TKinter are also not the same. That is what AddIns are for. Then you do have access to the ArcMap message queue and can detect all the mouse events such as the code you have pasted.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My solution is for the case when you want to select a box interactively at the start and then run a script, &lt;/SPAN&gt;&lt;SPAN style="text-decoration:underline;"&gt;not&lt;/SPAN&gt;&lt;SPAN&gt; using the AddIn objects. Since you can add a script tool as a button, this is almost equivalent to Avenue tools we were use to, and it is easy to implement.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=Feature%20sets%20and%20record%20sets" rel="nofollow noopener noreferrer" target="_blank"&gt;http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=Feature%20sets%20and%20record%20sets&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The Esri example concentrates on modelbuilder, but it can work in simple tools just as well.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Create a tool and add a parameter. Set it to featureset. Set a schema that is a polygon featureclass.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;When you run the tool, open the properties to set drawing rectangles&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Draw one or more rectangles and start the tool&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;In your script collect the polygon featureset entered interactively when the tool is run&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;This is just like an on-the-fly featureclass but in memory&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# DemoBox
# draw a box interactively and report extent
import arcpy
fSet = arcpy.GetParameter(0)
desc = arcpy.Describe(fSet)

# print a JSON representation, version 10.1
arcpy.AddMessage(str(desc.pjson))
# print the extent of each box version 9.3+
for row in arcpy.SearchCursor(fSet):
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(str(row.shape.extent))
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 13:24:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/draw-a-rectangle-by-dragging/m-p/274811#M21228</guid>
      <dc:creator>KimOllivier</dc:creator>
      <dc:date>2021-12-11T13:24:14Z</dc:date>
    </item>
    <item>
      <title>Re: Draw a rectangle by dragging</title>
      <link>https://community.esri.com/t5/python-questions/draw-a-rectangle-by-dragging/m-p/274812#M21229</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Dear Kimo&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You don't know how much your help is valuable for me. Thank you. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My question&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Can I use the last codes you gave me as a solution in my Tkinter because I definitely need a Tkinter widget GUI in my project? &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you for your help. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Best Regards &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Babak&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 02 Feb 2013 02:47:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/draw-a-rectangle-by-dragging/m-p/274812#M21229</guid>
      <dc:creator>babakkasraei</dc:creator>
      <dc:date>2013-02-02T02:47:00Z</dc:date>
    </item>
    <item>
      <title>Re: Draw a rectangle by dragging</title>
      <link>https://community.esri.com/t5/python-questions/draw-a-rectangle-by-dragging/m-p/274813#M21230</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;The featureset is part of the ArcGIS toolbox parameters. It does not use TKinter at all.&lt;BR /&gt;&lt;BR /&gt;Your code attempts to use objects only available using a full AddIn. &lt;BR /&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#//014p0000001q000000" rel="nofollow noopener noreferrer" target="_blank"&gt;http://resources.arcgis.com/en/help/main/10.1/index.html#//014p0000001q000000&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;You can use Tkinter to draw rectangles on a Tkinter window, but not the ArcMap window, so the coordinates will not be transformed to map units. The message queues between ArcGIS and TKinter are also not the same. That is what AddIns are for. Then you do have access to the ArcMap message queue and can detect all the mouse events such as the code you have pasted.&lt;BR /&gt;&lt;BR /&gt;My solution is for the case when you want to select a box interactively at the start and then run a script, &lt;SPAN style="text-decoration:underline;"&gt;not&lt;/SPAN&gt; using the AddIn objects. Since you can add a script tool as a button, this is almost equivalent to Avenue tools we were use to, and it is easy to implement.&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=Feature%20sets%20and%20record%20sets" rel="nofollow noopener noreferrer" target="_blank"&gt;http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=Feature%20sets%20and%20record%20sets&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;The Esri example concentrates on modelbuilder, but it can work in simple tools just as well.&lt;BR /&gt;&lt;BR /&gt;Create a tool and add a parameter. Set it to featureset. Set a schema that is a polygon featureclass.&lt;BR /&gt;When you run the tool, open the properties to set drawing rectangles&lt;BR /&gt;Draw one or more rectangles and start the tool&lt;BR /&gt;In your script collect the polygon featureset entered interactively when the tool is run&lt;BR /&gt;This is just like an on-the-fly featureclass but in memory&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# DemoBox
# draw a box interactively and report extent
import arcpy
fSet = arcpy.GetParameter(0)
desc = arcpy.Describe(fSet)

# print a JSON representation, version 10.1
arcpy.AddMessage(str(desc.pjson))
# print the extent of each box version 9.3+
for row in arcpy.SearchCursor(fSet):
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(str(row.shape.extent))
&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dear Kim&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I tried the steps you have written. I created a model in my toolbox with Select by location tool. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I created a variable then I set it to feature set in my model. Then I added a schema to it which is a polygon feature set that I had been already created. finally I connected it to the selection tool. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Now as you wrote I need to run the tool and open the properties to set a rectangle drawing and draw some rectangles. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;your words&lt;/SPAN&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;&lt;BR /&gt;When you run the tool, open the properties to set drawing rectangles&lt;BR /&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt;I don't understand this step. How does it happen because my tool still needs a layer?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If I run the tool where will be the properties option?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Which properties do you mean? Properties of tool, model or variable. Where is the draw a rectangle option. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Next you have written&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;&lt;BR /&gt;&lt;BR /&gt;In your script collect the polygon featureset entered interactively when the tool is run&lt;BR /&gt;&lt;BR /&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Do you mean that I collect extent features by drawing a rectangle on my layer?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I really appreciate your clarification. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Best regards &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Babak&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 13:24:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/draw-a-rectangle-by-dragging/m-p/274813#M21230</guid>
      <dc:creator>babakkasraei</dc:creator>
      <dc:date>2021-12-11T13:24:17Z</dc:date>
    </item>
    <item>
      <title>Re: Draw a rectangle by dragging</title>
      <link>https://community.esri.com/t5/python-questions/draw-a-rectangle-by-dragging/m-p/274814#M21231</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Don't use a model, just create a script tool.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You set a schema to define the featureclass and fields in the dialog wizard when adding the parameters to the tool.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;It uses that schema to create a polygon when you draw interactively. It has to exist, you are not defining a new featureclass.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;After you open the tool there is a hidden property to change the drawing style by right-clicking the input in the tool dialog for the template properties.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It defaults to drawing a polygon, but you can change it to draw a box. It requires a line and then drag which is a bit strange but it enables you to draw a box at any angle. But you can right click again and set a horizontal property.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You would use the feature to select other layers directly, I only printed the json dump and the extent to demonstrate that it is a polygon feature that can be used in other tools or in Python.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 03 Feb 2013 07:16:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/draw-a-rectangle-by-dragging/m-p/274814#M21231</guid>
      <dc:creator>KimOllivier</dc:creator>
      <dc:date>2013-02-03T07:16:05Z</dc:date>
    </item>
    <item>
      <title>Re: Draw a rectangle by dragging</title>
      <link>https://community.esri.com/t5/python-questions/draw-a-rectangle-by-dragging/m-p/274815#M21232</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Dear Kim&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I did it successfully. I put my parameter as Feature set. When the Schema appeared I gave it an empty shape file. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So as soon as I open the dialogue my cursor starts drawing a rectangle. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Now I have two problems. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1- I need my rectangle to be hollow, because when draw the rectangle, it covers the other layers. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;2- I want to embed these codes into my Tkinter to work by pushing button1 click. I found the following codes for entering the schema into python codes&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

&amp;nbsp; from json_schema import Schema, AnyInteger

&amp;nbsp; my_schema = Schema([u"set-temp", {u"degrees": AnyInteger}]) 

&amp;nbsp; if my_schema.validate([u"set-temp", {u"degrees": 10}]):
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Valid!"
&lt;/PRE&gt;&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Do you think it is possible? How?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I hope you help me. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Best regards &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Babak&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 13:24:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/draw-a-rectangle-by-dragging/m-p/274815#M21232</guid>
      <dc:creator>babakkasraei</dc:creator>
      <dc:date>2021-12-11T13:24:19Z</dc:date>
    </item>
    <item>
      <title>Re: Draw a rectangle by dragging</title>
      <link>https://community.esri.com/t5/python-questions/draw-a-rectangle-by-dragging/m-p/274816#M21233</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Don't use a model, just create a script tool.&lt;BR /&gt;&lt;BR /&gt;You set a schema to define the featureclass and fields in the dialog wizard when adding the parameters to the tool.&lt;BR /&gt;It uses that schema to create a polygon when you draw interactively. It has to exist, you are not defining a new featureclass.&lt;BR /&gt;&lt;BR /&gt;After you open the tool there is a hidden property to change the drawing style by right-clicking the input in the tool dialog for the template properties.&lt;BR /&gt;&lt;BR /&gt;It defaults to drawing a polygon, but you can change it to draw a box. It requires a line and then drag which is a bit strange but it enables you to draw a box at any angle. But you can right click again and set a horizontal property.&lt;BR /&gt;&lt;BR /&gt;You would use the feature to select other layers directly, I only printed the json dump and the extent to demonstrate that it is a polygon feature that can be used in other tools or in Python.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hi Kim&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I created the following codes in my Tkinter for button1 function. It works; however, I still have problem because I have to create a feature set parameter by a schema and then draw my rectangle before running the tool. After running the tool when I select a layer from the list and push button1 the place that I have selected get highlight, so it works, but I want it to work when I push the button not before it. following you can see my button1 codes. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

def button1Click(self, selection):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Import arcpy module
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; import arcpy
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; index = self.listbox.curselection()&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; label = self.listbox.get(index) 

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Local variables:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; layer = label

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Script arguments
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Feature_Set = arcpy.GetParameterAsText(0)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if Feature_Set == '#' or not Feature_Set:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Feature_Set = "in_memory\\{EDD8060B-E74A-42D1-93A5-7CB08285BA52}" # provide a default value if unspecified

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Local variables:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CHS_Chart_Extents__3_ = Feature_Set
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CHS_Chart_Extents = layer

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Process: Select Layer By Location
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByLocation_management(CHS_Chart_Extents, "WITHIN", Feature_Set, "", "NEW_SELECTION")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshActiveView()

&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I appreciate your help &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Best regards&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Babak&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 13:24:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/draw-a-rectangle-by-dragging/m-p/274816#M21233</guid>
      <dc:creator>babakkasraei</dc:creator>
      <dc:date>2021-12-11T13:24:22Z</dc:date>
    </item>
    <item>
      <title>Re: Draw a rectangle by dragging</title>
      <link>https://community.esri.com/t5/python-questions/draw-a-rectangle-by-dragging/m-p/274817#M21234</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You change the draw symbol by defining a layer with the symbol you need and use that as the schema in the parameter property.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Using a tool at the start is the only way before 10.1 to interactively draw a box with python scripting unless you use .NET and ArcObjects.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have no idea how you are using TKinter inside your script, so I cannot help you further. I have used TKinter for some forms and feedback, but not to interact with the map page. I have already mentioned that the TKinter message queue is not the same as the ArcMap queue.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For a much better interactive experience, use the 10.1 AddIns that allow you to have interactive control of the mouse from inside a python tool. You can have buttons in an AddIn that initiate dragging a box, in fact the Esri example in the help is exactly that.&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#//014p00000025000000"&gt;AddIns&lt;/A&gt;&lt;BR /&gt;&lt;SPAN&gt;To make an AddIn you have to download the AddIn Wizard, program up a loop that watches for windows events, and responds to them. Event based programming is very different from the batch style programming used in the geoprocessing tools. Once the scripts have been written correctly and tested for syntax errors, they have to be assembled into a folder of resources and installed. Then you must restart ArcMap to test the AddIn. For any script edits you have to close down ArcMap and repeat the compilation and installation, and then re-open ArcMap. It is fairly difficult and tedious to debug. That is why I suggested you abandon Tkinter and get the rectangle first using an easy-to-program geoprocessing tool.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you want a robust and reliable process in ArcMap with interaction using the mouse then use AddIns with Python or .NET and C#.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Feb 2013 07:39:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/draw-a-rectangle-by-dragging/m-p/274817#M21234</guid>
      <dc:creator>KimOllivier</dc:creator>
      <dc:date>2013-02-04T07:39:27Z</dc:date>
    </item>
    <item>
      <title>Re: Draw a rectangle by dragging</title>
      <link>https://community.esri.com/t5/python-questions/draw-a-rectangle-by-dragging/m-p/274818#M21235</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you Kim &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Your help was really important for me. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Drawing a shape before running the tool is OK. I go for other buttons. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Best regards &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Babak&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Feb 2013 22:08:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/draw-a-rectangle-by-dragging/m-p/274818#M21235</guid>
      <dc:creator>babakkasraei</dc:creator>
      <dc:date>2013-02-04T22:08:45Z</dc:date>
    </item>
  </channel>
</rss>

