<?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: NameError: global name is not defined when Python script is run from ArcMap. in Python AddIns Questions</title>
    <link>https://community.esri.com/t5/python-addins-questions/nameerror-global-name-is-not-defined-when-python/m-p/1027494#M139</link>
    <description>&lt;P&gt;In most cases, this error is triggered when Python sees a variable name (Global or Local) and doesn't know what it's for. These errors can happen if you forget to initialize a variable , if you misspell a variable, or if you misspell a reserved word such as "True". Before you use the &lt;A href="http://net-informations.com/python/iq/global.htm" target="_self"&gt;global variable&lt;/A&gt; in your function for reading, it must be first initialized somewhere: either outside of the function or inside it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 17 Feb 2021 06:10:40 GMT</pubDate>
    <dc:creator>geraldwarp</dc:creator>
    <dc:date>2021-02-17T06:10:40Z</dc:date>
    <item>
      <title>NameError: global name is not defined when Python script is run from ArcMap.</title>
      <link>https://community.esri.com/t5/python-addins-questions/nameerror-global-name-is-not-defined-when-python/m-p/785898#M45</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Continuing on in learning Python as I go I am at the next issue.&amp;nbsp; I have created a Python toolbar add-in with a button for use in ArcMap.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Start up ArcMap, toolbar is there, select button and a menu I created in Python is displayed.&amp;nbsp; It contains radiobuttons and comboboxes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;On the reset button I want to clear the radiobuttons, clear the selected item from the combobox so it is not selected-blue, and set the combobox back to the first item in the list.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When I run the script from PyScripter the menu appears and I can clear and reset everything so the menu looks like it just loaded.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When I start ArcMap the Python toolbar appears, select the button, menu appears, select a radiobutton, select an item from a combobox, that all works.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When I select the reset button I get the following error whether it is a radiobutton or a combobox:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have the python window open in ArcMap so I can see what is happening.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Exception in Tkinter callback&lt;BR /&gt;Traceback (most recent call last):&lt;BR /&gt; File "C:\Python27\ArcGIS10.5\Lib\lib-tk\Tkinter.py", line 1542, in __call__&lt;BR /&gt; return self.func(*args)&lt;BR /&gt; File "D:\Applications\Python\Layers.py", line 63, in reset&lt;BR /&gt; RB1.selection_clear = var.set(0)&lt;BR /&gt;NameError: global name 'RB1' is not defined&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is beyond my knowledge at this point, I did try to set a global variable with no change to the error message.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;These are my import statements for the script:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;from tkinter import *&lt;BR /&gt;from tkinter import ttk&lt;BR /&gt;import tkFont&lt;BR /&gt;import arcpy&lt;BR /&gt;from arcpy import env&lt;BR /&gt;import sqlite3&lt;BR /&gt;import pythonaddins&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am not putting in all the code, for now it is all radiobuttons and comboboxes, very repetitive.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is the code I have concerning 'RB1':&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;def reset():&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;RB1.selection_clear = var.set(0)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;RB1 = Radiobutton(root, text="Single Map",padx = 5, variable=var, value=1, font="Arial 9") #, state=NORMAL).place(x=10,y=60)&lt;BR /&gt;RB1.pack()&lt;BR /&gt;RB1.place(x=10,y=60)&lt;BR /&gt;RB1.config(state=NORMAL)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Button(root, text='Reset',width=20,bg='brown',fg='white', font="Arial 8 bold", command=reset).place(x=39,y=237)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As this is my first Python script ever, and for use within ArcMap, I am sure there are a few things I am missing.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for looking at my question.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 May 2019 20:58:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-addins-questions/nameerror-global-name-is-not-defined-when-python/m-p/785898#M45</guid>
      <dc:creator>DaleShearer</dc:creator>
      <dc:date>2019-05-10T20:58:04Z</dc:date>
    </item>
    <item>
      <title>Re: NameError: global name is not defined when Python script is run from ArcMap.</title>
      <link>https://community.esri.com/t5/python-addins-questions/nameerror-global-name-is-not-defined-when-python/m-p/785899#M46</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I haven't worked a lot with add-ins,&amp;nbsp; but I have experienced issues with script tools and Python toolboxes not working well with global variables.&amp;nbsp; I think it has to do with how/where the global is declared and function calls.&amp;nbsp; This link may give some&amp;nbsp; insight, but won't directly answer your question: &lt;A href="https://gis.stackexchange.com/questions/156939"&gt;Python toolbox tool objects do not remember instance variables between function calls?&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 May 2019 21:36:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-addins-questions/nameerror-global-name-is-not-defined-when-python/m-p/785899#M46</guid>
      <dc:creator>RandyBurton</dc:creator>
      <dc:date>2019-05-10T21:36:30Z</dc:date>
    </item>
    <item>
      <title>Re: NameError: global name is not defined when Python script is run from ArcMap.</title>
      <link>https://community.esri.com/t5/python-addins-questions/nameerror-global-name-is-not-defined-when-python/m-p/785900#M47</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;As Richard said in this thread &amp;nbsp;&lt;A _jive_internal="true" class="link-titled" href="https://community.esri.com/message/379045?commentID=379045#comment-379045" title="https://community.esri.com/message/379045?commentID=379045#comment-379045"&gt;https://community.esri.com/message/379045?commentID=379045#comment-379045&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Tk isn't supported in ArcMap.&lt;/P&gt;&lt;P&gt;A search of other grief filled threads on GeoNet are available for perusal... ArcMap TkInter … will give you many old ones.&amp;nbsp; some glimmers of hope, a few workarounds, but everything is going to be situation specific.&amp;nbsp; It is just best not to let the two play together in the first place&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 May 2019 22:18:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-addins-questions/nameerror-global-name-is-not-defined-when-python/m-p/785900#M47</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2019-05-10T22:18:58Z</dc:date>
    </item>
    <item>
      <title>Re: NameError: global name is not defined when Python script is run from ArcMap.</title>
      <link>https://community.esri.com/t5/python-addins-questions/nameerror-global-name-is-not-defined-when-python/m-p/785901#M48</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the replies, as Tkinter does not work well with ArcMap, what advice-direction can you give me as how to develop a menu in Python for use in ArcMap, basically where to start at again.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 May 2019 16:00:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-addins-questions/nameerror-global-name-is-not-defined-when-python/m-p/785901#M48</guid>
      <dc:creator>DaleShearer</dc:creator>
      <dc:date>2019-05-13T16:00:46Z</dc:date>
    </item>
    <item>
      <title>Re: NameError: global name is not defined when Python script is run from ArcMap.</title>
      <link>https://community.esri.com/t5/python-addins-questions/nameerror-global-name-is-not-defined-when-python/m-p/1027494#M139</link>
      <description>&lt;P&gt;In most cases, this error is triggered when Python sees a variable name (Global or Local) and doesn't know what it's for. These errors can happen if you forget to initialize a variable , if you misspell a variable, or if you misspell a reserved word such as "True". Before you use the &lt;A href="http://net-informations.com/python/iq/global.htm" target="_self"&gt;global variable&lt;/A&gt; in your function for reading, it must be first initialized somewhere: either outside of the function or inside it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Feb 2021 06:10:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-addins-questions/nameerror-global-name-is-not-defined-when-python/m-p/1027494#M139</guid>
      <dc:creator>geraldwarp</dc:creator>
      <dc:date>2021-02-17T06:10:40Z</dc:date>
    </item>
  </channel>
</rss>

