Select to view content in your preferred language

Cannot exit a Python Script from ArcMap

640
1
Jump to solution
05-10-2019 08:42 AM
DaleShearer
Frequent Contributor

Thanks for looking at my question.

I have a Python toolbar with a button that runs a Python script that displays a menu box.  This is being ran through ArcMap.  I open my mxd, display the menu, now I want to close it when I am finished and that is the problem.

I am calling:

def quit():
      root.destroy()

to close the menu from a button command.

When I run the script in pyscripter and display the menu box and hit the close button it works.

When I have the menu box open in ArcMap and hit the close button I get the following error:

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 49, in quit
root.destroy()
NameError: global name 'root' is not defined

The next issue I see is how to close the Python box when I close ArcMap.

Thanks for looking at my question.

0 Kudos
1 Solution

Accepted Solutions
DaleShearer
Frequent Contributor

Well, fixed this, I put root.destroy in the command on the Button and it closes the menu box when being ran from ArcMap.

Button(root, text='Close',width=20,bg='brown',fg='white', font="Arial 8 bold", command=root.destroy).place(x=39,y=272)

View solution in original post

0 Kudos
1 Reply
DaleShearer
Frequent Contributor

Well, fixed this, I put root.destroy in the command on the Button and it closes the menu box when being ran from ArcMap.

Button(root, text='Close',width=20,bg='brown',fg='white', font="Arial 8 bold", command=root.destroy).place(x=39,y=272)

0 Kudos