| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 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 |
|
| 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 |
|
| 47 |
|
| 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) |