From: cgw at fnal.gov (Charles G Waldman)
Date: Mon, 12 Apr 1999 21:07:04 GMT
Subject: Stupid Tkinter question
In-Reply-To: <99041222110400.01382@dominion>
References: <99041222110400.01382@dominion>
Message-ID: <14098.24696.77181.178918@buffalo.fnal.gov>
X-UID: 1710                                                  

Bjoern Giesler writes:

 > I'm going crazy. Why does this fragment work (adapted from imageview.py
 > in Guido's Tkinter demos):
 >  [snip]
 > .... but this doesn't:
 >  [snip]
 >
 > def makeToolbar(aFrame):
 >   toolbar = Frame(aFrame)
 >   markimage = BitmapImage(file = "Mark.xbm")
 >   markbutton = Button(toolbar,
 >                       image = markimage,
 >                       command = exit)
 >
 >   markbutton.pack()
 >   return toolbar

The "markimage" object goes out of scope when makeToolbar exits, and
storage for the image automatically gets cleared up.  You need to
cause there to be a persistent reference to the image object.
Fortunately this is pretty easy to do.  Try this:

def makeToolbar(aFrame):
   toolbar = Frame(aFrame)
   toolbar.markimage = BitmapImage(file = "Mark.xbm")
   markbutton = Button(toolbar,
                       image = toolbar.markimage,
                       command = exit)

   markbutton.pack()
   return toolbar



