Select to view content in your preferred language

Displaying features/rasters/GDBs as single files with TkFileDialog.askopenfilename

3861
5
07-23-2015 09:41 AM
RachaelJohnson
Deactivated User

I'm building a GUI for users to input their data with Tkinter and TkFileDialog. 

When I use TkFileDialog, it gives me a list of the individual files that Windows sees when I am trying to pick my file (top image), but I really want it to merge those files together to form one cohesive file like ArcCatalog does automatically (bottom image). 

I'm pretty sure my users are going to be up in arms about what file to pick if I don't make an effort to change it.  I know I can specify the extensions that show and that is a reasonable workaround. However, a user is completely unable to select files from a .GDB in this way.  I can think of a workaround for this but I would rather not have to do that as it is very labor intensive and makes me add a lot of extra parts to my GUI. 

file_example.jpg

I found IGxObjectFilter​ but that appears to not be a Python thing.  Is there a way to read the files cohesively within Python?

0 Kudos
5 Replies
AlexanderNohe1
Honored Contributor

If I was you, I would skip making a file picker using TKinter and use the pythonaddins module to select the files.  This will automatically group the common file types together and might be able to provide a little more control.

import pythonaddins
pythonaddins.OpenDialog()

More documentation on this can be found here:

ArcGIS Help 10.1

I hope this helps!

RachaelJohnson
Deactivated User

Oh no, I thought this would work but that module only works when the code is being used within GIS.  Still, it's very helpful for anyone who isn't making a standalone script.

I wish I could set your answer to "90% correct answer" because in most situations, it would be the way to solve my problem!

0 Kudos
AlexanderNohe1
Honored Contributor

My mistake, I misread the documentation as it being able to be used in stand-alone scripts.

What version of ArcMap are you using?

0 Kudos
RachaelJohnson
Deactivated User

I'm using 10.3 with the latest version of Python 2. 

0 Kudos
AlexanderNohe1
Honored Contributor

I have been looking more into this recently this afternoon.  The only options that I can think of (both are untested) are:

1) Use IronPython and access the ArcObjects DLLs and launch the GxDialog. (Not sure how that will interact with your current script and that would require an additional install on several users machines).

2)  Create the GxDialog using ArcObjects .NET and then using standard i/0 pipes, launch the exe to get the dialog box and then pass the data back to Python.

Neither of these may be feasible for you.

0 Kudos