| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
import Tix, os, copy |
| 20 |
from Tkconstants import * |
| 21 |
|
| 22 |
TCL_ALL_EVENTS = 0 |
| 23 |
|
| 24 |
def RunSample (root): |
| 25 |
dirlist = DemoDirList(root) |
| 26 |
dirlist.mainloop() |
| 27 |
dirlist.destroy() |
| 28 |
|
| 29 |
class DemoDirList: |
| 30 |
def __init__(self, w): |
| 31 |
self.root = w |
| 32 |
self.exit = -1 |
| 33 |
|
| 34 |
z = w.winfo_toplevel() |
| 35 |
z.wm_protocol("WM_DELETE_WINDOW", lambda self=self: self.quitcmd()) |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
top = Tix.Frame( w, relief=RAISED, bd=1) |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
top.dir = Tix.DirList(top) |
| 50 |
top.dir.hlist['width'] = 40 |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
top.btn = Tix.Button(top, text = " >> ", pady = 0) |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
top.ent = Tix.LabelEntry(top, label="Installation Directory:", |
| 62 |
labelside = 'top', |
| 63 |
options = ''' |
| 64 |
entry.width 40 |
| 65 |
label.anchor w |
| 66 |
''') |
| 67 |
|
| 68 |
font = self.root.tk.eval('tix option get fixed_font') |
| 69 |
|
| 70 |
top.ent.entry['font'] = font |
| 71 |
|
| 72 |
self.dlist_dir = copy.copy(os.curdir) |
| 73 |
|
| 74 |
top.ent.entry['textvariable'] = self.dlist_dir |
| 75 |
top.btn['command'] = lambda dir=top.dir, ent=top.ent, self=self: \ |
| 76 |
self.copy_name(dir,ent) |
| 77 |
|
| 78 |
|
| 79 |
top.ent.entry.bind('<Return>', lambda self=self: self.okcmd () ) |
| 80 |
|
| 81 |
top.pack( expand='yes', fill='both', side=TOP) |
| 82 |
top.dir.pack( expand=1, fill=BOTH, padx=4, pady=4, side=LEFT) |
| 83 |
top.btn.pack( anchor='s', padx=4, pady=4, side=LEFT) |
| 84 |
top.ent.pack( expand=1, fill=X, anchor='s', padx=4, pady=4, side=LEFT) |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
box = Tix.ButtonBox (w, orientation='horizontal') |
| 89 |
box.add ('ok', text='Ok', underline=0, width=6, |
| 90 |
command = lambda self=self: self.okcmd () ) |
| 91 |
box.add ('cancel', text='Cancel', underline=0, width=6, |
| 92 |
command = lambda self=self: self.quitcmd () ) |
| 93 |
|
| 94 |
box.pack( anchor='s', fill='x', side=BOTTOM) |
| 95 |
|
| 96 |
def copy_name (self, dir, ent): |
| 97 |
|
| 98 |
self.dlist_dir = dir.cget('value') |
| 99 |
|
| 100 |
ent.entry.delete(0,'end') |
| 101 |
ent.entry.insert(0, self.dlist_dir) |
| 102 |
|
| 103 |
def okcmd (self): |
| 104 |
|
| 105 |
self.quitcmd() |
| 106 |
|
| 107 |
def quitcmd (self): |
| 108 |
self.exit = 0 |
| 109 |
|
| 110 |
def mainloop(self): |
| 111 |
while self.exit < 0: |
| 112 |
self.root.tk.dooneevent(TCL_ALL_EVENTS) |
| 113 |
|
| 114 |
def destroy (self): |
| 115 |
self.root.destroy() |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
if __name__== '__main__' : |
| 121 |
import tkMessageBox, traceback |
| 122 |
|
| 123 |
try: |
| 124 |
root=Tix.Tk() |
| 125 |
RunSample(root) |
| 126 |
except: |
| 127 |
t, v, tb = sys.exc_info() |
| 128 |
text = "Error running the demo script:\n" |
| 129 |
for line in traceback.format_exception(t,v,tb): |
| 130 |
text = text + line + '\n' |
| 131 |
d = tkMessageBox.showerror ( 'Tix Demo Error', text) |