I am trying to insert the output of a SparQL query (via rdflib) into a listbox in a Tkinter GUI. The current version of the code is:
Button_4 = Button(self, text="Load object list", command=self.populateListbox)
Button_4.grid(row=14, column=0, sticky=N)
self.List_3 = Listbox(self, height=7, width=40, selectmode='single', exportselection=0)
self.List_3.grid(row=15, column=0, sticky=N)
def populateListbox(self):
g=rdflib.Graph()
filename = r'bim\Perceel4.owl'
g.load(filename, format='xml')
Layer = u'Asfaltplak_onderlaag'
qres = g.query(
"""SELECT DISTINCT ?value ?name ?file ?frag
WHERE {
-- SparQL query for results--
}""",
initNs=dict(
cbim=Namespace("http://www.coinsweb.nl/cbim-1.1.owl#")))
for row in qres:
if (rdflib.term.Literal(Layer, datatype=rdflib.term.URIRef(u'http://www.w3.org/2001/XMLSchema#string')) in row):
self.lst = row['file']
self.List_3.insert("end",self.lst)
If I print the SparQL query using the command: print: self.lst, I get the following print message:
DTB HRB 166.495 - 166.038 VH_gml.xml
DTB OPR 167.647 - 167.601 VH_gml.xml
DTB PST 170.824 - 170.769 VH_gml.xml
DTB HRB 166.038 - 164.169 VH_gml.xml
DTB PST 167.696 - 167.767 VH_gml.xml
...etc (more of these filenames)
When I run the program and click on the button to populate the listbox, I only get one name in the listbox, namely the first one of the list. How can I get the entire list inserted in the listbox, such as it comes out the print command?
Ps. I tried the '*' by using self.List_3.insert("end",self.*lst), but that only splits the name into a list that consist of the name split, as such:
D
T
S
1
2
..etc
U p d a t e :
I have added the list split as such:
...
output = row['file']
self.lst = output.split("\n")
self.List_3.insert("end",*self.lst)
but it still only gives one list entry in the listbox (the last one of the list). If I print self.lst in the new setup, it prints:
[u'DTB HRB 167.639 - 167.696 VH_gml.xml']
[u'DTB PST 167.134 - 167.274 VH_gml.xml']
[u'DTB HRB 166.038 - 164.169 VH_gml.xml']
...etc