I tried to specify a feature class from a GDB dataset through Python Tkinter tkFileDialog.askopenfilename. Below is the script. It worked for me in the past when I was dealing with .txt or .las files. However, this time it is not giving me the GDB feature class, which has no file extension here. Please advise.
import arcpy
from arcpy import env
import Tkinter,tkFileDialog
from Tkinter import *
import tkMessageBox
import ttk
from tkFileDialog import askopenfilename
from tkFileDialog import askopenfile
env.workspace = "C:\\temp\\miniPilot\\miniPilot.gdb"
def browseFor_inFC():
inFC_name = tkFileDialog.askopenfilename(parent=root, initialdir=r'C:\temp\miniPilot\miniPilot.gdb\data', \
title='Choose a feature class')
inFC.set(inFC_name)
def cancel():
root.destroy()
def remove():
fields = arcpy.ListFields(inFC)
for field in fields:
print field.name
if field.name <> "OBJECTID" and field.name <> "SHAPE" and field.name <> "SHAPE_Length":
arcpy.DeleteField_management(inFC, field.name)
root=Tk()
root.title("XXXXXX")
# The first frame named 'mainframe'
mainframe = Frame(root, relief='flat', borderwidth=6)
mainframe.grid(column=0, row=0, sticky=(N, W, E, S))
mainframe.columnconfigure(0, weight=1)
mainframe.rowconfigure(0, weight=1)
# set up Tkinter variables, which are global variables, for the first gui -- the root window
inFC = StringVar()
# widgets on the mainframe
Label(mainframe, text="Specify the feature class: ").grid(column=1, row=1, sticky=E)
inFC_entry = Entry(mainframe, width=36, textvariable=inFC)
inFC_entry.grid(column=2, row=1, sticky=(W, E))
inFC_browser_Button=Button(mainframe, text="...", height=1, width=3, command=browseFor_inFC).grid(column=3, row=1, sticky=W)
# two button widgets
refract_Button=Button(mainframe, text="OK", command=remove).grid(column=0, row=2, sticky=E)
cancel_Button=Button(mainframe, text="CANCEL", command=cancel).grid(column=4, row=3, sticky=W)
for child in mainframe.winfo_children(): child.grid_configure(padx=5, pady=5)
root.mainloop() # create an event loop
pythonaddins.OpenDialog
?