[Tutor] event binding

Isaac Hall hall@nhn.ou.edu
Wed, 10 Apr 2002 13:15:44 -0500


Hi everyone:

I was wondering if anyone with Tkinter experience and/or Pmw experience can
help me

Right now I have this class we will call MyClass for this letter
and there are several instances of MyClass gridded in a notebook,  one per page.

Now MyClass is set to display some histograms and such (defined by another
class, but that isnt the important part).....so without trying to explain too
much, Ill give you example code


class MyClass(Frame):
	def __init__(self, parent, <otherstuff>):
		<do something not really important with the otherstuff>
		self.bind("<Visibility>", self.update_graphics)  #IMPORTANT

	def onUpdate(self):
		if self.winfo_viewable:
			<update our display>	
		#this guy exists so we can also update from outside
		#the class (but only if we can see it)
		<do some other not really important stuff>

	def update_graphics(self, event):
		self.onUpdate()


so as you can see here, the idea is that the outside can call the update
function but the graphics only get updated (since this takes up most of the
time for the program) when we are looking at the instance of MyClass.
and if we happen to switch pages in between updates from the outside, the
MyClass instance we switch to should call its update method and pop up the
pretty pictures.  However, this does not seem to work as planned.  Instead the
updating takes place twice when pages are switched (and although I can probably
work around that bug, I would rather have it not exist)  so I am wondering if
there is anything I am doing wrong in order to have this happen the way I want
it to.  Like maybe a better event binding to use or something,  or even a
self-defined event (I don't feel comfortable making those), so if someone could
help here, (even if it is to show me how to create events to bind to, wether or
not that is helpful in this case) I would greatly appreciate it.

Thank you in advance  :)

Ike