Martin v. Löwis | 8ec03e0 | 2002-03-17 18:19:13 +0000 | [diff] [blame] | 1 | # -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*- |
| 2 | # |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 3 | # $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öwis | 8ec03e0 | 2002-03-17 18:19:13 +0000 | [diff] [blame] | 8 | # executed from the Tix demo program "tixwidgets.py": it must have a |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 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 | # 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 Peterson | d6d63f5 | 2009-01-04 18:53:28 +0000 | [diff] [blame] | 18 | import tkinter.tix |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 19 | |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 20 | TCL_ALL_EVENTS = 0 |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 21 | |
Martin v. Löwis | 8ec03e0 | 2002-03-17 18:19:13 +0000 | [diff] [blame] | 22 | def RunSample (root): |
| 23 | balloon = DemoBalloon(root) |
| 24 | balloon.mainloop() |
| 25 | balloon.destroy() |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 26 | |
Martin v. Löwis | 8ec03e0 | 2002-03-17 18:19:13 +0000 | [diff] [blame] | 27 | class DemoBalloon: |
| 28 | def __init__(self, w): |
| 29 | self.root = w |
| 30 | self.exit = -1 |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 31 | |
Martin v. Löwis | 8ec03e0 | 2002-03-17 18:19:13 +0000 | [diff] [blame] | 32 | z = w.winfo_toplevel() |
| 33 | z.wm_protocol("WM_DELETE_WINDOW", lambda self=self: self.quitcmd()) |
| 34 | |
Benjamin Peterson | d6d63f5 | 2009-01-04 18:53:28 +0000 | [diff] [blame] | 35 | 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öwis | 8ec03e0 | 2002-03-17 18:19:13 +0000 | [diff] [blame] | 37 | |
| 38 | # Create two mysterious widgets that need balloon help |
Benjamin Peterson | d6d63f5 | 2009-01-04 18:53:28 +0000 | [diff] [blame] | 39 | button1 = tkinter.tix.Button(w, text='Something Unexpected', |
Martin v. Löwis | 8ec03e0 | 2002-03-17 18:19:13 +0000 | [diff] [blame] | 40 | command=self.quitcmd) |
Benjamin Peterson | d6d63f5 | 2009-01-04 18:53:28 +0000 | [diff] [blame] | 41 | button2 = tkinter.tix.Button(w, text='Something Else Unexpected') |
Martin v. Löwis | 8ec03e0 | 2002-03-17 18:19:13 +0000 | [diff] [blame] | 42 | button2['command'] = lambda w=button2: w.destroy() |
Benjamin Peterson | d6d63f5 | 2009-01-04 18:53:28 +0000 | [diff] [blame] | 43 | button1.pack(side=tkinter.tix.TOP, expand=1) |
| 44 | button2.pack(side=tkinter.tix.TOP, expand=1) |
Martin v. Löwis | 8ec03e0 | 2002-03-17 18:19:13 +0000 | [diff] [blame] | 45 | |
| 46 | # Create the balloon widget and associate it with the widgets that we want |
| 47 | # to provide tips for: |
Benjamin Peterson | d6d63f5 | 2009-01-04 18:53:28 +0000 | [diff] [blame] | 48 | b = tkinter.tix.Balloon(w, statusbar=status) |
Martin v. Löwis | 8ec03e0 | 2002-03-17 18:19:13 +0000 | [diff] [blame] | 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() |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 65 | |
| 66 | if __name__ == '__main__': |
Benjamin Peterson | d6d63f5 | 2009-01-04 18:53:28 +0000 | [diff] [blame] | 67 | root = tkinter.tix.Tk() |
Martin v. Löwis | b21cb5f | 2001-03-21 07:42:07 +0000 | [diff] [blame] | 68 | RunSample(root) |