Home | History | Annotate | Download | only in samples
      1 # -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
      2 #
      3 # $Id$
      4 #
      5 # Tix Demonstration Program
      6 #
      7 # This sample program is structured in such a way so that it can be
      8 # executed from the Tix demo program "tixwidgets.py": it must have a
      9 # procedure called "RunSample". It should also have the "if" statment
     10 # at the end of this file so that it can be run as a standalone
     11 # program.
     12 
     13 # This file demonstrates the use of the tixBalloon widget, which provides
     14 # an interesting way to give help tips about elements in your user interface.
     15 # Your can display the help message in a "balloon" and a status bar widget.
     16 #
     17 
     18 import Tix
     19 
     20 TCL_ALL_EVENTS          = 0
     21 
     22 def RunSample (root):
     23     balloon = DemoBalloon(root)
     24     balloon.mainloop()
     25     balloon.destroy()
     26 
     27 class DemoBalloon:
     28     def __init__(self, w):
     29         self.root = w
     30         self.exit = -1
     31 
     32         z = w.winfo_toplevel()
     33         z.wm_protocol("WM_DELETE_WINDOW", lambda self=self: self.quitcmd())
     34 
     35         status = Tix.Label(w, width=40, relief=Tix.SUNKEN, bd=1)
     36         status.pack(side=Tix.BOTTOM, fill=Tix.Y, padx=2, pady=1)
     37 
     38         # Create two mysterious widgets that need balloon help
     39         button1 = Tix.Button(w, text='Something Unexpected',
     40                              command=self.quitcmd)
     41         button2 = Tix.Button(w, text='Something Else Unexpected')
     42         button2['command'] = lambda w=button2: w.destroy()
     43         button1.pack(side=Tix.TOP, expand=1)
     44         button2.pack(side=Tix.TOP, expand=1)
     45 
     46         # Create the balloon widget and associate it with the widgets that we want
     47         # to provide tips for:
     48         b = Tix.Balloon(w, statusbar=status)
     49 
     50         b.bind_widget(button1, balloonmsg='Close Window',
     51                       statusmsg='Press this button to close this window')
     52         b.bind_widget(button2, balloonmsg='Self-destruct button',
     53                       statusmsg='Press this button and it will destroy itself')
     54 
     55     def quitcmd (self):
     56         self.exit = 0
     57 
     58     def mainloop(self):
     59         foundEvent = 1
     60         while self.exit < 0 and foundEvent > 0:
     61             foundEvent = self.root.tk.dooneevent(TCL_ALL_EVENTS)
     62 
     63     def destroy (self):
     64         self.root.destroy()
     65 
     66 if __name__ == '__main__':
     67     root = Tix.Tk()
     68     RunSample(root)
     69