[SOLVED]image destroy doesn't work


#1

Why the following doesn’t work?

I’m getting an error: global name ‘np’ is not defined.

class BttnPrss(DirectObject):
	def __init__(self):
		self.accept("p",self.addbg)
		self.accept("o",self.rembg)
	def addbg(self):
		np=OnscreenImage('image.jpg')
		np.setPos(0, 1, 0.8)
    	return np
	def rembg(self):
		np.destroy()
		return

#2

Replace “np” with “self.np”, and this snippet will work.

EDIT: Post #150! :slight_smile:


#3

Yes, that solves it. Many thanks!