| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
import Tix |
| 17 |
|
| 18 |
TCL_ALL_EVENTS = 0 |
| 19 |
|
| 20 |
def RunSample (root): |
| 21 |
shlist = DemoSHList(root) |
| 22 |
shlist.mainloop() |
| 23 |
shlist.destroy() |
| 24 |
|
| 25 |
class DemoSHList: |
| 26 |
def __init__(self, w): |
| 27 |
self.root = w |
| 28 |
self.exit = -1 |
| 29 |
|
| 30 |
z = w.winfo_toplevel() |
| 31 |
z.wm_protocol("WM_DELETE_WINDOW", lambda self=self: self.quitcmd()) |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
top = Tix.Frame( w, relief=Tix.RAISED, bd=1) |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
top.a = Tix.ScrolledHList(top) |
| 42 |
top.a.pack( expand=1, fill=Tix.BOTH, padx=10, pady=10, side=Tix.TOP) |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
bosses = [ |
| 47 |
('jeff', 'Jeff Waxman'), |
| 48 |
('john', 'John Lee'), |
| 49 |
('peter', 'Peter Kenson') |
| 50 |
] |
| 51 |
|
| 52 |
employees = [ |
| 53 |
('alex', 'john', 'Alex Kellman'), |
| 54 |
('alan', 'john', 'Alan Adams'), |
| 55 |
('andy', 'peter', 'Andreas Crawford'), |
| 56 |
('doug', 'jeff', 'Douglas Bloom'), |
| 57 |
('jon', 'peter', 'Jon Baraki'), |
| 58 |
('chris', 'jeff', 'Chris Geoffrey'), |
| 59 |
('chuck', 'jeff', 'Chuck McLean') |
| 60 |
] |
| 61 |
|
| 62 |
hlist=top.a.hlist |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
hlist.config( separator='.', width=25, drawbranch=0, indent=10) |
| 67 |
|
| 68 |
count=0 |
| 69 |
for boss,name in bosses : |
| 70 |
if count : |
| 71 |
f=Tix.Frame(hlist, name='sep%d' % count, height=2, width=150, |
| 72 |
bd=2, relief=Tix.SUNKEN ) |
| 73 |
|
| 74 |
hlist.add_child( itemtype=Tix.WINDOW, |
| 75 |
window=f, state=Tix.DISABLED ) |
| 76 |
|
| 77 |
hlist.add(boss, itemtype=Tix.TEXT, text=name) |
| 78 |
count = count+1 |
| 79 |
|
| 80 |
|
| 81 |
for person,boss,name in employees : |
| 82 |
|
| 83 |
|
| 84 |
key= boss + '.' + person |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
hlist.add( key, text=name ) |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
box= Tix.ButtonBox(top, orientation=Tix.HORIZONTAL ) |
| 103 |
box.add( 'ok', text='Ok', underline=0, width=6, |
| 104 |
command = self.okcmd) |
| 105 |
|
| 106 |
box.add( 'cancel', text='Cancel', underline=0, width=6, |
| 107 |
command = self.quitcmd) |
| 108 |
|
| 109 |
box.pack( side=Tix.BOTTOM, fill=Tix.X) |
| 110 |
top.pack( side=Tix.TOP, fill=Tix.BOTH, expand=1 ) |
| 111 |
|
| 112 |
def okcmd (self): |
| 113 |
self.quitcmd() |
| 114 |
|
| 115 |
def quitcmd (self): |
| 116 |
self.exit = 0 |
| 117 |
|
| 118 |
def mainloop(self): |
| 119 |
while self.exit < 0: |
| 120 |
self.root.tk.dooneevent(TCL_ALL_EVENTS) |
| 121 |
|
| 122 |
def destroy (self): |
| 123 |
self.root.destroy() |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
if __name__== '__main__' : |
| 130 |
root=Tix.Tk() |
| 131 |
RunSample(root) |