3

The following script works great from the command line but crashes from the pythonaddin:

import Tkinter

import tkFileDialog
root = Tkinter.Tk()
root.withdraw()
pathtest = tkFileDialog.askopenfilename()
print pathtest

pathtest = pythonaddins.OpenDialog('Open Item', True) does not work for me because it suppresses filetypes that I need to see (pdf).

I know this is a duplicate question but I just joined the site and could not comment on other posts.

  • 1
    Using Tkinter or any other python gui-library is not supported for python-addins. The only supported option is using C#/arcobjects instead. – warrieka Apr 27 '15 at 15:07
  • Anyone have an idea of how to use the pythonaddins.OpenDialog() without it suppressing file extensions. – Brad Jeffares Apr 27 '15 at 16:14
  • pythonaddins.OpenDialog is only for browsing for spatial datasets. You could try PyQT per the suggestion by Jason Scheirer (an ESRI software developer) in the question you linked to. – user2856 Apr 28 '15 at 00:52
  • Will I have the same issue with PyQT that I had with Tkinter? – Brad Jeffares Apr 28 '15 at 17:30
  • @Brad No idea, never tried it. But given that the suggestion was made by an ESRI employee (who I understand developed much of the ArcGIS python stack), I suggest you give it a go. – user2856 Apr 29 '15 at 04:13

2 Answers2

1

It is technically possible to use Tkinter in arcpy / python addins using multiprocessing, but this is quite complicated and not supported or recommended by ESRI. They recommend using C# instead of python for GUI development.

See this post and http://anothergisblog.blogspot.se/2013/07/python-add-ins-and-tkinter.html

warrieka
  • 3,479
  • 17
  • 18
0

You could try using native win32 dialogs. You'd need to have pywin32 installed first (pip installable version is pypiwin32), then you could do something like:

import win32ui
dlg = win32ui.CreateFileDialog(1, ".pdf", "Default File Name.pdf", 
                               0, "PDF Files (*.pdf)|*.pdf|All Files (*.*)|*.*|")
dlg.DoModal()
print dlg.GetPathName()
del dlg
user2856
  • 65,736
  • 6
  • 115
  • 196