2

这很像一个旅行推销员问题。我有一个包含大学名称的列表框(以我从 Facebook 图表中获取的坐标为后盾)。我将选择模式设置为多个。我需要知道允许我使用他们选择的大学的代码,以便我可以通过距离方法对他们进行介绍。我只需要知道代码就可以看到他们选择了什么。我尝试使用 curselection() 但我仍然不明白。

这是一些代码:

    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)
4

1 回答 1

2

很高兴看到您如何尝试使用 curselection 来查看问题所在。

就像是:

for idx in self.listbox.curselection():
    selitem = self.listbox.get(idx)

应该做的伎俩。你试过吗?

于 2012-05-15T06:59:25.943 回答