python - More Issues with overlapping labels in Tkinter -


i having problem tkinter. issue follows.

i retrieve information database. wish print out based off few user selections. want print out columns a, b, c want print out columns, a, b, c, d want print out columns a, b, d, e

also, when query, not know ahead of time how many results have. queries give 1. give 200. print them, this...

            while x < results.num_rows() :                 result = results.fetch_row()                 author = result[0][0]                 title = result[0][1]                 conference = result[0][2]                 year = result[0][3]                 location = result[0][4]                 label(root, text=title).grid(row=startrow,column=0,columnspan=5,sticky=w)                 label(root,text=author).grid(row=startrow,column=6,columnspan=1,sticky=w)                 label(root,text=year).grid(row=startrow,column=7,columnspan=1,sticky=w)                 label(root,text=conference).grid(row=startrow,column=8,columnspan=1,sticky=w)                 label(root,text=location).grid(row=startrow,column=9,columnspan=1,sticky=w)                 startrow+=1                 x+=1 

this accomplishes want. label printed below previous each item. prints desired columns (in case, title, author, year, conference, location). different. it's good.

until user query. can't delete previous labels. have no reference them. can't make reference them, because dont know ahead of time how many need. number of labels based off of query user wants , matching entries in database.

so when user 2nd or 3rd query, results start printed on top of 1 another.

what can do?

edit - attempt. added in

    try :         item in labellist :             item.grid_forget()     except :         pass 

i put @ beginning of button code, if labellist exists, @ each query. if doesn't exist, pass.

            while x < results.num_rows() :                 result = results.fetch_row()                 title = result[0][0]                 conference = result[0][1]                 year = result[0][2]                 location = result[0][3]                 message = title + "\t\t\t\t\t" + conference + "\t" + str(year) + "\t" + location                 label = label(root, text=title)                 label.grid(row=startrow, column=0, columnspan=5,sticky=w)                 labellist.append(label)                 label = label(root, text=conference)                 label.grid(row=startrow, column=6, columnspan=1,sticky=w)                 labellist.append( label )                 label = label(root, text=year)                 label.grid(row=startrow, column=7, columnspan=1,sticky=w)                 labellist.append( label )                 label = label(root, text=location)                 label.grid(row=startrow, column=8, columnspan=1,sticky=w)                 labellist.append( label )                 startrow+=1                 x+=1 

however still getting overlapping issue.

if have lot of widgets, can store id's in list , destroy each one, or place them in new frame , destroy frame each time, removes reference widget's in it. personally, reuse labels of results 1 query, i.e. attach textvariable each one, set textvariable new value each record found, or "" if empty. see http://effbot.org/tkinterbook/label.htm info on textvariable option labels.

def next_set_of_recs():     print "next set"     old_frame.destroy()  top = tk.tk() tk.label(top, text="not in created frame").grid()  old_frame=tk.frame(top) old_frame.grid(row=1) tk.label(old_frame, text="a_label", width=50).grid() ## give time, otherwise instantly destroyed top.after(2000, next_set_of_recs)    top.mainloop() 

Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -