Continuing on in learning Python as I go I am at the next issue. I have created a Python toolbar add-in with a button for use in ArcMap.
Start up ArcMap, toolbar is there, select button and a menu I created in Python is displayed. It contains radiobuttons and comboboxes.
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.
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.
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.
When I select the reset button I get the following error whether it is a radiobutton or a combobox:
I have the python window open in ArcMap so I can see what is happening.
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python27\ArcGIS10.5\Lib\lib-tk\Tkinter.py", line 1542, in __call__
return self.func(*args)
File "D:\Applications\Python\Layers.py", line 63, in reset
RB1.selection_clear = var.set(0)
NameError: global name 'RB1' is not defined
This is beyond my knowledge at this point, I did try to set a global variable with no change to the error message.
These are my import statements for the script:
from tkinter import *
from tkinter import ttk
import tkFont
import arcpy
from arcpy import env
import sqlite3
import pythonaddins
I am not putting in all the code, for now it is all radiobuttons and comboboxes, very repetitive.
This is the code I have concerning 'RB1':
def reset():
RB1.selection_clear = var.set(0)
RB1 = Radiobutton(root, text="Single Map",padx = 5, variable=var, value=1, font="Arial 9") #, state=NORMAL).place(x=10,y=60)
RB1.pack()
RB1.place(x=10,y=60)
RB1.config(state=NORMAL)
Button(root, text='Reset',width=20,bg='brown',fg='white', font="Arial 8 bold", command=reset).place(x=39,y=237)
As this is my first Python script ever, and for use within ArcMap, I am sure there are a few things I am missing.
Thank you for looking at my question.