Hi folks,
I was wondering if there was some way to delete all Labels from a Tkinter canvas in one go. I'm not even sure if the labels are being drawn on the canvas since you only use the master(self.root) when creating it but I do the same for buttons and self.canvas.delete(ALL) is working for that. The labels are being created in a seperate class but the buttons are not. The class where self.canvas.delete(ALL) is being called is the same one as where the buttons are being created. Darn, I didn't want to post the code since it was so messy but I'll do it. Here it is. Please help:
from Tkinter import *
from PIL import Image, ImageTk
class Slot(object):
def __init__(self,root,canvas,appimg,x,y):
self.root=root
self.canvas=canvas
self.l=Label(self.root,image=appimg)
self.l.place(x=x,y=y)
class View(object):
def __init__(self,canvas):
self.canvas=canvas
class win1(View):
def draw(self,root,pl,tv):
self.canvas.delete(ALL)
self.root=root
self.photolist=pl
self.tv=tv
self.s=Slot(self.root,self.canvas,self.photolist[0],10,10)
self.qbtn1=Button(self.root,text="quit",command=lambda:self.quit(self.tv))
self.qbtn1.place(x=270,y=100)
def quit(self,tv):
self.tv[1].draw(self.root,self.photolist,self.tv)
class win2(View):
def draw(self,root,pl,tv):
self.canvas.delete(ALL)
self.root=root
self.photolist=pl
self.tv=tv
self.s2=Slot(self.root,self.canvas,self.photolist[1],270,10)
self.qbtn2=Button(self.root,text="quit2",command=lambda:self.quit(self.tv))
self.qbtn2.place(x=100,y=10)
def quit(self,tv):
self.tv[0].draw(self.root,self.photolist,self.tv)
class win3(View):
def draw(self):
pass
class App(object):
def openAllImgs(self):
self.photolist=[]
image=Image.open("pic1.bmp")
photo1=ImageTk.PhotoImage(image)
self.photolist.append(photo1)
image=Image.open("pic2.bmp")
photo2=ImageTk.PhotoImage(image)
self.photolist.append(photo2)
def __init__(self, width=640, height=480):
self.width = width
self.height = height
self.root = Tk()
self.root.title("tkinter_test01")
self.root.geometry("%sx%s"%(self.width, self.height))
self.canvas = Canvas(self.root, width=self.width, height=self.height)
self.theviews=[win1(self.canvas),win2(self.canvas),win3(self.canvas)]
self.openAllImgs()
self.theviews[0].draw(self.root,self.photolist,self.theviews)
self.canvas.pack()
self.root.mainloop()
app=App()