I've been looking for a way to enter a unique field name into an attribute table for up to 40 feature classes. I need the field names to be meaningful, not just 'field1', 'field2' etc. For example, if the feature class represents wetlands I would like a field called 'Wetland'.
I thought the easiest way of doing this would be to use TKinter. I can print the feature class name and then dynamically enter a field name with the TKinter data entry msgbox. Then keep looping through the feature classes until they all have a field with a unique name.
I've found some examples but am unsure about how to use data entry text as a variable in Python. If anyone out there had an example script or can make suggestions on this script I'd appreciate it:
import arcpy
from arcpy import env
from Tkinter import *
# Environment Workspace
env.workspace = r'G:\TEST\Python_Test\Test.gdb'
def receive():
text = E1.get()
print (text)
top = Tk()
L1 = Label(top, text="User Name")
L1.pack( side = LEFT)
E1 = Entry(top, bd =5)
E1.pack(side = RIGHT)
b = Button(top, text="OK", width=10, command=receive)
b.pack()
top.mainloop()
Best Answer
I managed to figure this out... My code now iterates through feature classes, requests a field name, calculates fields, deletes unwanted fields. And then joins the left over fields to each other with a spatial join. I was stuck on adding the interactive tkinter dialog box in the first loop, and the delete field text at the end of the first loop. I still have some to do on this, but thought I'd post the answers to my original question. Thought I'd put my code up for others: