无法识别在另一个命令中使用Listbox中的返回项目。收到一条消息,说"myBuff"
不是字段名称。 myBuff
应该以字符串形式返回吗?其他时候我收到此消息:TypeError: selectBuffer() takes exactly 2 arguments (1 given)
import arcpy,sys,os
from Tkinter import*
class Application(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.grid()
self.createWidgets(master)
def createWidgets(self,master):
#add listbox and populate it
self.bufList = Listbox(master, height=4, width=17, selectmode=SINGLE)
self.bufList.grid(row=0, column=0, rowspan=4, columnspan=2, sticky='w')
self.bufList.insert(END, "Select A Buffer")
for item in ["5m", "10m", "15m"]:
self.bufList.insert(END, item)
#add Select Button
self.selectButton = Button(master, text='1. Select',command=self.selectBuffer)
self.selectButton.grid(row=0, column=2, sticky='nw')
self.selectButton.bind("<<ListboxSelect>>", self.selectBuffer)
#add method for select button
def selectBuffer(self, event):
global select
select = self.bufList.curselection()
myBuff = self.bufList.get(select[0]) #get value of selected item
#perform geoprocessing analysis
mxd = arcpy.mapping.MapDocument("C:/Projects/MyProject.mxd)
arcpy.Buffer_analysis("C:/Projects/road.shp", "C:/Projects/roadBuffer100.shp","myBuff")
root = Tk()
app = Application(master=root)
app.mainloop()
答案 0 :(得分:0)
您使用selectBuffer
两次。
command=self.selectBuffer
self.selectButton.bind("<<ListboxSelect>>", self.selectBuffer)
其中一行预计def selectBuffer(self, event):
,
另一个期待def selectBuffer(self):
所以你得到错误。
使用None
作为event
的默认值来解决问题。
def selectBuffer(self, event=None):