Python 2.7 如何从列表框中存储用户选择的输入
这很像旅行推销员的问题。我有一个列表框,里面有大学的名字(后面是我从Facebook的图表中获取的坐标)。我已将选择模式设置为“多个”。我需要知道允许我使用他们选择的学院的代码,这样我就可以通过一种距离法来输入它们。我只需要知道代码就可以看到他们选择了什么。我试着使用curseelection(),但还是不明白 下面是一些代码:Python 2.7 如何从列表框中存储用户选择的输入,python-2.7,Python 2.7,这很像旅行推销员的问题。我有一个列表框,里面有大学的名字(后面是我从Facebook的图表中获取的坐标)。我已将选择模式设置为“多个”。我需要知道允许我使用他们选择的学院的代码,这样我就可以通过一种距离法来输入它们。我只需要知道代码就可以看到他们选择了什么。我试着使用curseelection(),但还是不明白 下面是一些代码: self.listbox = Listbox(self.mid_frame,width = 42,selectmode ="multiple",
self.listbox = Listbox(self.mid_frame,width = 42,selectmode ="multiple",
highlightcolor = "orange",
highlightthickness = "10",bd = "5")
coordinates = []
collegelist = []
f = open(sys.argv[1],'r')
# grab the college's lat and long from facebook graph
for identity in f:
urlquery='https://graph.facebook.com/'+identity
obj = json.load(urllib2.urlopen(urlquery))
college = obj["name"]
latitude = obj["location"]["latitude"]
longitude = obj["location"]["longitude"]
coordinates.append((college,latitude, longitude))
collegelist.append(college)
#sort the colleges so they appear alphabetical order
sortcollege = sorted(collegelist)
#fill Listbox with the College names imported from a text file
for college in sortcollege:
self.listbox.insert(END, college)
self.listbox.pack(side = LEFT)
#The label where I would put the total distance
self.output_totaldist_label = Label(self.mid_frame,
width = 11,
textvariable = self.totaldistance)
self.totaldistance = StringVar()
self.output_label = Label(self.mid_frame,
textvariable = self.totaldistance)
self.output_totaldist_label.pack(side = LEFT)
self.output_label.pack(side = LEFT)
如果能看到你是如何试图找出问题所在的,那就太好了 比如:
for idx in self.listbox.curselection():
selitem = self.listbox.get(idx)
我们应该做到这一点。你试过了吗?是的,这很有帮助。非常感谢你。