blob: bc25a2ef67ccf13a655495cb5107f9a318d107f7 [file] [log] [blame]
Martin v. Löwis8ec03e02002-03-17 18:19:13 +00001# -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
2#
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00003# $Id$
4#
5# Tix Demostration Program
6#
7# This sample program is structured in such a way so that it can be
Martin v. Löwis8ec03e02002-03-17 18:19:13 +00008# executed from the Tix demo program "tixwidgets.py": it must have a
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +00009# 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# a 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
Benjamin Petersond6d63f52009-01-04 18:53:28 +000018import tkinter.tix
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000019
Tim Peters182b5ac2004-07-18 06:16:08 +000020TCL_ALL_EVENTS = 0
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000021
Martin v. Löwis8ec03e02002-03-17 18:19:13 +000022def RunSample (root):
23 balloon = DemoBalloon(root)
24 balloon.mainloop()
25 balloon.destroy()
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000026
Martin v. Löwis8ec03e02002-03-17 18:19:13 +000027class DemoBalloon:
28 def __init__(self, w):
29 self.root = w
30 self.exit = -1
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000031
Martin v. Löwis8ec03e02002-03-17 18:19:13 +000032 z = w.winfo_toplevel()
33 z.wm_protocol("WM_DELETE_WINDOW", lambda self=self: self.quitcmd())
34
Benjamin Petersond6d63f52009-01-04 18:53:28 +000035 status = tkinter.tix.Label(w, width=40, relief=tkinter.tix.SUNKEN, bd=1)
36 status.pack(side=tkinter.tix.BOTTOM, fill=tkinter.tix.Y, padx=2, pady=1)
Martin v. Löwis8ec03e02002-03-17 18:19:13 +000037
38 # Create two mysterious widgets that need balloon help
Benjamin Petersond6d63f52009-01-04 18:53:28 +000039 button1 = tkinter.tix.Button(w, text='Something Unexpected',
Martin v. Löwis8ec03e02002-03-17 18:19:13 +000040 command=self.quitcmd)
Benjamin Petersond6d63f52009-01-04 18:53:28 +000041 button2 = tkinter.tix.Button(w, text='Something Else Unexpected')
Martin v. Löwis8ec03e02002-03-17 18:19:13 +000042 button2['command'] = lambda w=button2: w.destroy()
Benjamin Petersond6d63f52009-01-04 18:53:28 +000043 button1.pack(side=tkinter.tix.TOP, expand=1)
44 button2.pack(side=tkinter.tix.TOP, expand=1)
Martin v. Löwis8ec03e02002-03-17 18:19:13 +000045
46 # Create the balloon widget and associate it with the widgets that we want
47 # to provide tips for:
Benjamin Petersond6d63f52009-01-04 18:53:28 +000048 b = tkinter.tix.Balloon(w, statusbar=status)
Martin v. Löwis8ec03e02002-03-17 18:19:13 +000049
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()
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000065
66if __name__ == '__main__':
Benjamin Petersond6d63f52009-01-04 18:53:28 +000067 root = tkinter.tix.Tk()
Martin v. Löwisb21cb5f2001-03-21 07:42:07 +000068 RunSample(root)