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.
-
1Using Tkinter or any other python gui-library is not supported for python-addins. The only supported option is using C#/arcobjects instead.warrieka– warrieka2015年04月27日 15:07:03 +00:00Commented Apr 27, 2015 at 15:07
-
Anyone have an idea of how to use the pythonaddins.OpenDialog() without it suppressing file extensions.Brad Jeffares– Brad Jeffares2015年04月27日 16:14:05 +00:00Commented Apr 27, 2015 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– user28562015年04月28日 00:52:08 +00:00Commented Apr 28, 2015 at 0:52
-
Will I have the same issue with PyQT that I had with Tkinter?Brad Jeffares– Brad Jeffares2015年04月28日 17:30:27 +00:00Commented Apr 28, 2015 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– user28562015年04月29日 04:13:47 +00:00Commented Apr 29, 2015 at 4:13
2 Answers 2
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
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
Explore related questions
See similar questions with these tags.