1
# -*-mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
3
# $Id: tixwidgets.py 68309 2009-01-04 18:53:28Z benjamin.peterson $
7
# For Tix, see http://tix.sourceforge.net
9
# This is a demo program of some of the Tix widgets available in Python.
10
# If you have installed Python & Tix properly, you can execute this as
12
# % python tixwidgets.py
15
import os, os.path, sys, tkinter.tix
16
from tkinter.constants import *
17
import traceback, tkinter.messagebox
20
TCL_WINDOW_EVENTS = 1<<2
21
TCL_FILE_EVENTS = 1<<3
22
TCL_TIMER_EVENTS = 1<<4
23
TCL_IDLE_EVENTS = 1<<5
27
def __init__(self, top):
31
self.dir = None # script directory
32
self.balloon = None # balloon widget
33
self.useBalloons = tkinter.tix.StringVar()
34
self.useBalloons.set('0')
35
self.statusbar = None # status bar widget
36
self.welmsg = None # Msg widget
37
self.welfont = '' # font name
38
self.welsize = '' # font size
40
progname = sys.argv[0]
41
dirname = os.path.dirname(progname)
42
if dirname and dirname != os.curdir:
45
for i in range(len(sys.path)):
47
if p in ("", os.curdir):
50
sys.path[index] = dirname
52
sys.path.insert(0, dirname)
54
self.dir = os.getcwd()
55
sys.path.insert(0, self.dir+'/samples')
59
w = tkinter.tix.Frame(top, bd=2, relief=RAISED)
60
file = tkinter.tix.Menubutton(w, text='File', underline=0, takefocus=0)
61
help = tkinter.tix.Menubutton(w, text='Help', underline=0, takefocus=0)
64
fm = tkinter.tix.Menu(file, tearoff=0)
66
hm = tkinter.tix.Menu(help, tearoff=0)
69
fm.add_command(label='Exit', underline=1,
70
command = lambda self=self: self.quitcmd () )
71
hm.add_checkbutton(label='BalloonHelp', underline=0, command=ToggleHelp,
72
variable=self.useBalloons)
73
# The trace variable option doesn't seem to work, instead I use 'command'
74
#w.tk.call('trace', 'variable', self.useBalloons, 'w', ToggleHelp))
78
def MkMainNotebook(self):
80
w = tkinter.tix.NoteBook(top, ipadx=5, ipady=5, options="""
85
# This may be required if there is no *Background option
88
w.add('wel', label='Welcome', underline=0,
89
createcmd=lambda w=w, name='wel': MkWelcome(w, name))
90
w.add('cho', label='Choosers', underline=0,
91
createcmd=lambda w=w, name='cho': MkChoosers(w, name))
92
w.add('scr', label='Scrolled Widgets', underline=0,
93
createcmd=lambda w=w, name='scr': MkScroll(w, name))
94
w.add('mgr', label='Manager Widgets', underline=0,
95
createcmd=lambda w=w, name='mgr': MkManager(w, name))
96
w.add('dir', label='Directory List', underline=0,
97
createcmd=lambda w=w, name='dir': MkDirList(w, name))
98
w.add('exp', label='Run Sample Programs', underline=0,
99
createcmd=lambda w=w, name='exp': MkSample(w, name))
102
def MkMainStatus(self):
106
w = tkinter.tix.Frame(top, relief=tkinter.tix.RAISED, bd=1)
107
demo.statusbar = tkinter.tix.Label(w, relief=tkinter.tix.SUNKEN, bd=1)
108
demo.statusbar.form(padx=3, pady=3, left=0, right='%70')
113
z = root.winfo_toplevel()
114
z.wm_title('Tix Widget Demonstration')
115
if z.winfo_screenwidth() <= 800:
116
z.geometry('790x590+10+10')
118
z.geometry('890x640+10+10')
119
demo.balloon = tkinter.tix.Balloon(root)
120
frame1 = self.MkMainMenu()
121
frame2 = self.MkMainNotebook()
122
frame3 = self.MkMainStatus()
123
frame1.pack(side=TOP, fill=X)
124
frame3.pack(side=BOTTOM, fill=X)
125
frame2.pack(side=TOP, expand=1, fill=BOTH, padx=4, pady=4)
126
demo.balloon['statusbar'] = demo.statusbar
127
z.wm_protocol("WM_DELETE_WINDOW", lambda self=self: self.quitcmd())
129
# To show Tcl errors - uncomment this to see the listbox bug.
130
# Tkinter defines a Tcl tkerror procedure that in effect
131
# silences all background Tcl error reporting.
132
# root.tk.eval('if {[info commands tkerror] != ""} {rename tkerror pytkerror}')
134
"""Quit our mainloop. It is up to you to call root.destroy() after."""
138
"""This is an explict replacement for _tkinter mainloop()
139
It lets you catch keyboard interrupts easier, and avoids
140
the 20 msec. dead sleep() which burns a constant CPU."""
142
# There are 2 whiles here. The outer one lets you continue
143
# after a ^C interrupt.
145
# This is the replacement for _tkinter mainloop()
146
# It blocks waiting for the next Tcl event using select.
148
self.root.tk.dooneevent(TCL_ALL_EVENTS)
150
# Tkinter uses SystemExit to exit
154
except KeyboardInterrupt:
155
if tkinter.messagebox.askquestion ('Interrupt', 'Really Quit?') == 'yes':
156
# self.tk.eval('exit')
161
# Otherwise it's some other error - be nice and say why
162
t, v, tb = sys.exc_info()
164
for line in traceback.format_exception(t,v,tb):
166
try: tkinter.messagebox.showerror ('Error', text)
184
def MkWelcome(nb, name):
186
bar = MkWelcomeBar(w)
187
text = MkWelcomeText(w)
188
bar.pack(side=TOP, fill=X, padx=2, pady=2)
189
text.pack(side=TOP, fill=BOTH, expand=1)
191
def MkWelcomeBar(top):
194
w = tkinter.tix.Frame(top, bd=2, relief=tkinter.tix.GROOVE)
195
b1 = tkinter.tix.ComboBox(w, command=lambda w=top: MainTextFont(w))
196
b2 = tkinter.tix.ComboBox(w, command=lambda w=top: MainTextFont(w))
197
b1.entry['width'] = 15
198
b1.slistbox.listbox['height'] = 3
199
b2.entry['width'] = 4
200
b2.slistbox.listbox['height'] = 3
205
b1.insert(tkinter.tix.END, 'Courier')
206
b1.insert(tkinter.tix.END, 'Helvetica')
207
b1.insert(tkinter.tix.END, 'Lucida')
208
b1.insert(tkinter.tix.END, 'Times Roman')
210
b2.insert(tkinter.tix.END, '8')
211
b2.insert(tkinter.tix.END, '10')
212
b2.insert(tkinter.tix.END, '12')
213
b2.insert(tkinter.tix.END, '14')
214
b2.insert(tkinter.tix.END, '18')
219
b1.pack(side=tkinter.tix.LEFT, padx=4, pady=4)
220
b2.pack(side=tkinter.tix.LEFT, padx=4, pady=4)
222
demo.balloon.bind_widget(b1, msg='Choose\na font',
223
statusmsg='Choose a font for this page')
224
demo.balloon.bind_widget(b2, msg='Point size',
225
statusmsg='Choose the font size for this page')
228
def MkWelcomeText(top):
231
w = tkinter.tix.ScrolledWindow(top, scrollbar='auto')
233
text = 'Welcome to TIX in Python'
234
title = tkinter.tix.Label(win,
235
bd=0, width=30, anchor=tkinter.tix.N, text=text)
236
msg = tkinter.tix.Message(win,
237
bd=0, width=400, anchor=tkinter.tix.N,
238
text='Tix is a set of mega-widgets based on TK. This program \
239
demonstrates the widgets in the Tix widget set. You can choose the pages \
240
in this window to look at the corresponding widgets. \n\n\
241
To quit this program, choose the "File | Exit" command.\n\n\
242
For more information, see http://tix.sourceforge.net.')
243
title.pack(expand=1, fill=tkinter.tix.BOTH, padx=10, pady=10)
244
msg.pack(expand=1, fill=tkinter.tix.BOTH, padx=10, pady=10)
253
font = demo.welfont['value']
254
point = demo.welsize['value']
255
if font == 'Times Roman':
257
fontstr = '%s %s' % (font, point)
258
demo.welmsg['font'] = fontstr
261
if demo.useBalloons.get() == '1':
262
demo.balloon['state'] = 'both'
264
demo.balloon['state'] = 'none'
266
def MkChoosers(nb, name):
268
options = "label.padX 4"
270
til = tkinter.tix.LabelFrame(w, label='Chooser Widgets', options=options)
271
cbx = tkinter.tix.LabelFrame(w, label='tixComboBox', options=options)
272
ctl = tkinter.tix.LabelFrame(w, label='tixControl', options=options)
273
sel = tkinter.tix.LabelFrame(w, label='tixSelect', options=options)
274
opt = tkinter.tix.LabelFrame(w, label='tixOptionMenu', options=options)
275
fil = tkinter.tix.LabelFrame(w, label='tixFileEntry', options=options)
276
fbx = tkinter.tix.LabelFrame(w, label='tixFileSelectBox', options=options)
277
tbr = tkinter.tix.LabelFrame(w, label='Tool Bar', options=options)
288
# First column: comBox and selector
289
cbx.form(top=0, left=0, right='%33')
290
sel.form(left=0, right='&'+str(cbx), top=cbx)
291
opt.form(left=0, right='&'+str(cbx), top=sel, bottom=-1)
293
# Second column: title .. etc
294
til.form(left=cbx, top=0,right='%66')
295
ctl.form(left=cbx, right='&'+str(til), top=til)
296
fil.form(left=cbx, right='&'+str(til), top=ctl)
297
tbr.form(left=cbx, right='&'+str(til), top=fil, bottom=-1)
300
# Third column: file selection
301
fbx.form(right=-1, top=0, left='%66')
304
options="label.width %d label.anchor %s entry.width %d" % (10, tkinter.tix.E, 14)
306
static = tkinter.tix.ComboBox(w, label='Static', editable=0, options=options)
307
editable = tkinter.tix.ComboBox(w, label='Editable', editable=1, options=options)
308
history = tkinter.tix.ComboBox(w, label='History', editable=1, history=1,
309
anchor=tkinter.tix.E, options=options)
310
static.insert(tkinter.tix.END, 'January')
311
static.insert(tkinter.tix.END, 'February')
312
static.insert(tkinter.tix.END, 'March')
313
static.insert(tkinter.tix.END, 'April')
314
static.insert(tkinter.tix.END, 'May')
315
static.insert(tkinter.tix.END, 'June')
316
static.insert(tkinter.tix.END, 'July')
317
static.insert(tkinter.tix.END, 'August')
318
static.insert(tkinter.tix.END, 'September')
319
static.insert(tkinter.tix.END, 'October')
320
static.insert(tkinter.tix.END, 'November')
321
static.insert(tkinter.tix.END, 'December')
323
editable.insert(tkinter.tix.END, 'Angola')
324
editable.insert(tkinter.tix.END, 'Bangladesh')
325
editable.insert(tkinter.tix.END, 'China')
326
editable.insert(tkinter.tix.END, 'Denmark')
327
editable.insert(tkinter.tix.END, 'Ecuador')
329
history.insert(tkinter.tix.END, '/usr/bin/ksh')
330
history.insert(tkinter.tix.END, '/usr/local/lib/python')
331
history.insert(tkinter.tix.END, '/var/adm')
333
static.pack(side=tkinter.tix.TOP, padx=5, pady=3)
334
editable.pack(side=tkinter.tix.TOP, padx=5, pady=3)
335
history.pack(side=tkinter.tix.TOP, padx=5, pady=3)
337
states = ['Bengal', 'Delhi', 'Karnataka', 'Tamil Nadu']
339
def spin_cmd(w, inc):
340
idx = states.index(demo_spintxt.get()) + inc
342
idx = len(states) - 1
343
elif idx >= len(states):
345
# following doesn't work.
347
demo_spintxt.set(states[idx]) # this works
349
def spin_validate(w):
350
global states, demo_spintxt
353
i = states.index(demo_spintxt.get())
357
# why this procedure works as opposed to the previous one beats me.
362
options="label.width %d label.anchor %s entry.width %d" % (10, tkinter.tix.E, 13)
364
demo_spintxt = tkinter.tix.StringVar()
365
demo_spintxt.set(states[0])
366
simple = tkinter.tix.Control(w, label='Numbers', options=options)
367
spintxt = tkinter.tix.Control(w, label='States', variable=demo_spintxt,
369
spintxt['incrcmd'] = lambda w=spintxt: spin_cmd(w, 1)
370
spintxt['decrcmd'] = lambda w=spintxt: spin_cmd(w, -1)
371
spintxt['validatecmd'] = lambda w=spintxt: spin_validate(w)
373
simple.pack(side=tkinter.tix.TOP, padx=5, pady=3)
374
spintxt.pack(side=tkinter.tix.TOP, padx=5, pady=3)
377
options = "label.anchor %s" % tkinter.tix.CENTER
379
sel1 = tkinter.tix.Select(w, label='Mere Mortals', allowzero=1, radio=1,
380
orientation=tkinter.tix.VERTICAL,
381
labelside=tkinter.tix.TOP,
383
sel2 = tkinter.tix.Select(w, label='Geeks', allowzero=1, radio=0,
384
orientation=tkinter.tix.VERTICAL,
385
labelside= tkinter.tix.TOP,
388
sel1.add('eat', text='Eat')
389
sel1.add('work', text='Work')
390
sel1.add('play', text='Play')
391
sel1.add('party', text='Party')
392
sel1.add('sleep', text='Sleep')
394
sel2.add('eat', text='Eat')
395
sel2.add('prog1', text='Program')
396
sel2.add('prog2', text='Program')
397
sel2.add('prog3', text='Program')
398
sel2.add('sleep', text='Sleep')
400
sel1.pack(side=tkinter.tix.LEFT, padx=5, pady=3, fill=tkinter.tix.X)
401
sel2.pack(side=tkinter.tix.LEFT, padx=5, pady=3, fill=tkinter.tix.X)
404
options='menubutton.width 15 label.anchor %s' % tkinter.tix.E
406
m = tkinter.tix.OptionMenu(w, label='File Format : ', options=options)
407
m.add_command('text', label='Plain Text')
408
m.add_command('post', label='PostScript')
409
m.add_command('format', label='Formatted Text')
410
m.add_command('html', label='HTML')
412
m.add_command('tex', label='LaTeX')
413
m.add_command('rtf', label='Rich Text Format')
415
m.pack(fill=tkinter.tix.X, padx=5, pady=3)
418
msg = tkinter.tix.Message(w,
419
relief=tkinter.tix.FLAT, width=240, anchor=tkinter.tix.N,
420
text='Press the "open file" icon button and a TixFileSelectDialog will popup.')
421
ent = tkinter.tix.FileEntry(w, label='Select a file : ')
422
msg.pack(side=tkinter.tix.TOP, expand=1, fill=tkinter.tix.BOTH, padx=3, pady=3)
423
ent.pack(side=tkinter.tix.TOP, fill=tkinter.tix.X, padx=3, pady=3)
426
"""The FileSelectBox is a Motif-style box with various enhancements.
427
For example, you can adjust the size of the two listboxes
428
and your past selections are recorded.
430
msg = tkinter.tix.Message(w,
431
relief=tkinter.tix.FLAT, width=240, anchor=tkinter.tix.N,
432
text='The Tix FileSelectBox is a Motif-style box with various enhancements. For example, you can adjust the size of the two listboxes and your past selections are recorded.')
433
box = tkinter.tix.FileSelectBox(w)
434
msg.pack(side=tkinter.tix.TOP, expand=1, fill=tkinter.tix.BOTH, padx=3, pady=3)
435
box.pack(side=tkinter.tix.TOP, fill=tkinter.tix.X, padx=3, pady=3)
438
"""The Select widget is also good for arranging buttons in a tool bar.
442
options='frame.borderWidth 1'
444
msg = tkinter.tix.Message(w,
445
relief=tkinter.tix.FLAT, width=240, anchor=tkinter.tix.N,
446
text='The Select widget is also good for arranging buttons in a tool bar.')
447
bar = tkinter.tix.Frame(w, bd=2, relief=tkinter.tix.RAISED)
448
font = tkinter.tix.Select(w, allowzero=1, radio=0, label='', options=options)
449
para = tkinter.tix.Select(w, allowzero=0, radio=1, label='', options=options)
451
font.add('bold', bitmap='@' + demo.dir + '/bitmaps/bold.xbm')
452
font.add('italic', bitmap='@' + demo.dir + '/bitmaps/italic.xbm')
453
font.add('underline', bitmap='@' + demo.dir + '/bitmaps/underline.xbm')
454
font.add('capital', bitmap='@' + demo.dir + '/bitmaps/capital.xbm')
456
para.add('left', bitmap='@' + demo.dir + '/bitmaps/leftj.xbm')
457
para.add('right', bitmap='@' + demo.dir + '/bitmaps/rightj.xbm')
458
para.add('center', bitmap='@' + demo.dir + '/bitmaps/centerj.xbm')
459
para.add('justify', bitmap='@' + demo.dir + '/bitmaps/justify.xbm')
461
msg.pack(side=tkinter.tix.TOP, expand=1, fill=tkinter.tix.BOTH, padx=3, pady=3)
462
bar.pack(side=tkinter.tix.TOP, fill=tkinter.tix.X, padx=3, pady=3)
463
font.pack({'in':bar}, side=tkinter.tix.LEFT, padx=3, pady=3)
464
para.pack({'in':bar}, side=tkinter.tix.LEFT, padx=3, pady=3)
467
msg = tkinter.tix.Message(w,
468
relief=tkinter.tix.FLAT, width=240, anchor=tkinter.tix.N,
469
text='There are many types of "chooser" widgets that allow the user to input different types of information')
470
msg.pack(side=tkinter.tix.TOP, expand=1, fill=tkinter.tix.BOTH, padx=3, pady=3)
472
def MkScroll(nb, name):
474
options='label.padX 4'
476
sls = tkinter.tix.LabelFrame(w, label='Tix.ScrolledListBox', options=options)
477
swn = tkinter.tix.LabelFrame(w, label='Tix.ScrolledWindow', options=options)
478
stx = tkinter.tix.LabelFrame(w, label='Tix.ScrolledText', options=options)
484
sls.form(top=0, left=0, right='%33', bottom=-1)
485
swn.form(top=0, left=sls, right='%66', bottom=-1)
486
stx.form(top=0, left=swn, right=-1, bottom=-1)
490
"""This TixScrolledListBox is configured so that it uses scrollbars
491
only when it is necessary. Use the handles to resize the listbox and
492
watch the scrollbars automatically appear and disappear. """
493
top = tkinter.tix.Frame(w, width=300, height=330)
494
bot = tkinter.tix.Frame(w)
495
msg = tkinter.tix.Message(top,
496
relief=tkinter.tix.FLAT, width=200, anchor=tkinter.tix.N,
497
text='This TixScrolledListBox is configured so that it uses scrollbars only when it is necessary. Use the handles to resize the listbox and watch the scrollbars automatically appear and disappear.')
499
list = tkinter.tix.ScrolledListBox(top, scrollbar='auto')
500
list.place(x=50, y=150, width=120, height=80)
501
list.listbox.insert(tkinter.tix.END, 'Alabama')
502
list.listbox.insert(tkinter.tix.END, 'California')
503
list.listbox.insert(tkinter.tix.END, 'Montana')
504
list.listbox.insert(tkinter.tix.END, 'New Jersey')
505
list.listbox.insert(tkinter.tix.END, 'New York')
506
list.listbox.insert(tkinter.tix.END, 'Pennsylvania')
507
list.listbox.insert(tkinter.tix.END, 'Washington')
509
rh = tkinter.tix.ResizeHandle(top, bg='black',
510
relief=tkinter.tix.RAISED,
511
handlesize=8, gridded=1, minwidth=50, minheight=30)
512
btn = tkinter.tix.Button(bot, text='Reset', command=lambda w=rh, x=list: SList_reset(w,x))
514
msg.pack(fill=tkinter.tix.X)
515
btn.pack(anchor=tkinter.tix.CENTER)
516
top.pack(expand=1, fill=tkinter.tix.BOTH)
517
bot.pack(fill=tkinter.tix.BOTH)
518
list.bind('<Map>', func=lambda arg=0, rh=rh, list=list:
519
list.tk.call('tixDoWhenIdle', str(rh), 'attachwidget', str(list)))
521
def SList_reset(rh, list):
522
list.place(x=50, y=150, width=120, height=80)
524
rh.attach_widget(list)
527
"""The ScrolledWindow widget allows you to scroll any kind of Tk
528
widget. It is more versatile than a scrolled canvas widget.
532
text = 'The Tix ScrolledWindow widget allows you to scroll any kind of Tk widget. It is more versatile than a scrolled canvas widget.'
534
file = os.path.join(demo.dir, 'bitmaps', 'tix.gif')
535
if not os.path.isfile(file):
536
text += ' (Image missing)'
538
top = tkinter.tix.Frame(w, width=330, height=330)
539
bot = tkinter.tix.Frame(w)
540
msg = tkinter.tix.Message(top,
541
relief=tkinter.tix.FLAT, width=200, anchor=tkinter.tix.N,
544
win = tkinter.tix.ScrolledWindow(top, scrollbar='auto')
546
image1 = win.window.image_create('photo', file=file)
547
lbl = tkinter.tix.Label(win.window, image=image1)
548
lbl.pack(expand=1, fill=tkinter.tix.BOTH)
550
win.place(x=30, y=150, width=190, height=120)
552
rh = tkinter.tix.ResizeHandle(top, bg='black',
553
relief=tkinter.tix.RAISED,
554
handlesize=8, gridded=1, minwidth=50, minheight=30)
555
btn = tkinter.tix.Button(bot, text='Reset', command=lambda w=rh, x=win: SWindow_reset(w,x))
557
msg.pack(fill=tkinter.tix.X)
558
btn.pack(anchor=tkinter.tix.CENTER)
559
top.pack(expand=1, fill=tkinter.tix.BOTH)
560
bot.pack(fill=tkinter.tix.BOTH)
562
win.bind('<Map>', func=lambda arg=0, rh=rh, win=win:
563
win.tk.call('tixDoWhenIdle', str(rh), 'attachwidget', str(win)))
565
def SWindow_reset(rh, win):
566
win.place(x=30, y=150, width=190, height=120)
568
rh.attach_widget(win)
571
"""The TixScrolledWindow widget allows you to scroll any kind of Tk
572
widget. It is more versatile than a scrolled canvas widget."""
573
top = tkinter.tix.Frame(w, width=330, height=330)
574
bot = tkinter.tix.Frame(w)
575
msg = tkinter.tix.Message(top,
576
relief=tkinter.tix.FLAT, width=200, anchor=tkinter.tix.N,
577
text='The Tix ScrolledWindow widget allows you to scroll any kind of Tk widget. It is more versatile than a scrolled canvas widget.')
579
win = tkinter.tix.ScrolledText(top, scrollbar='auto')
580
win.text['wrap'] = 'none'
581
win.text.insert(tkinter.tix.END, '''When -scrollbar is set to "auto", the
582
scrollbars are shown only when needed.
583
Additional modifiers can be used to force a
584
scrollbar to be shown or hidden. For example,
585
"auto -y" means the horizontal scrollbar
586
should be shown when needed but the vertical
587
scrollbar should always be hidden;
588
"auto +x" means the vertical scrollbar
589
should be shown when needed but the horizontal
590
scrollbar should always be shown, and so on.'''
592
win.place(x=30, y=150, width=190, height=100)
594
rh = tkinter.tix.ResizeHandle(top, bg='black',
595
relief=tkinter.tix.RAISED,
596
handlesize=8, gridded=1, minwidth=50, minheight=30)
597
btn = tkinter.tix.Button(bot, text='Reset', command=lambda w=rh, x=win: SText_reset(w,x))
599
msg.pack(fill=tkinter.tix.X)
600
btn.pack(anchor=tkinter.tix.CENTER)
601
top.pack(expand=1, fill=tkinter.tix.BOTH)
602
bot.pack(fill=tkinter.tix.BOTH)
603
win.bind('<Map>', func=lambda arg=0, rh=rh, win=win:
604
win.tk.call('tixDoWhenIdle', str(rh), 'attachwidget', str(win)))
606
def SText_reset(rh, win):
607
win.place(x=30, y=150, width=190, height=120)
609
rh.attach_widget(win)
611
def MkManager(nb, name):
613
options='label.padX 4'
615
pane = tkinter.tix.LabelFrame(w, label='Tix.PanedWindow', options=options)
616
note = tkinter.tix.LabelFrame(w, label='Tix.NoteBook', options=options)
618
MkPanedWindow(pane.frame)
619
MkNoteBook(note.frame)
621
pane.form(top=0, left=0, right=note, bottom=-1)
622
note.form(top=0, right=-1, bottom=-1)
624
def MkPanedWindow(w):
625
"""The PanedWindow widget allows the user to interactively manipulate
626
the sizes of several panes. The panes can be arranged either vertically
629
msg = tkinter.tix.Message(w,
630
relief=tkinter.tix.FLAT, width=240, anchor=tkinter.tix.N,
631
text='The PanedWindow widget allows the user to interactively manipulate the sizes of several panes. The panes can be arranged either vertically or horizontally.')
632
group = tkinter.tix.LabelEntry(w, label='Newsgroup:', options='entry.width 25')
633
group.entry.insert(0,'comp.lang.python')
634
pane = tkinter.tix.PanedWindow(w, orientation='vertical')
636
p1 = pane.add('list', min=70, size=100)
637
p2 = pane.add('text', min=70)
638
list = tkinter.tix.ScrolledListBox(p1)
639
text = tkinter.tix.ScrolledText(p2)
641
list.listbox.insert(tkinter.tix.END, " 12324 Re: Tkinter is good for your health")
642
list.listbox.insert(tkinter.tix.END, "+ 12325 Re: Tkinter is good for your health")
643
list.listbox.insert(tkinter.tix.END, "+ 12326 Re: Tix is even better for your health (Was: Tkinter is good...)")
644
list.listbox.insert(tkinter.tix.END, " 12327 Re: Tix is even better for your health (Was: Tkinter is good...)")
645
list.listbox.insert(tkinter.tix.END, "+ 12328 Re: Tix is even better for your health (Was: Tkinter is good...)")
646
list.listbox.insert(tkinter.tix.END, " 12329 Re: Tix is even better for your health (Was: Tkinter is good...)")
647
list.listbox.insert(tkinter.tix.END, "+ 12330 Re: Tix is even better for your health (Was: Tkinter is good...)")
649
text.text['bg'] = list.listbox['bg']
650
text.text['wrap'] = 'none'
651
text.text.insert(tkinter.tix.END, """
652
Mon, 19 Jun 1995 11:39:52 comp.lang.python Thread 34 of 220
653
Lines 353 A new way to put text and bitmaps together iNo responses
654
ioi@blue.seas.upenn.edu Ioi K. Lam at University of Pennsylvania
658
I have implemented a new image type called "compound". It allows you
659
to glue together a bunch of bitmaps, images and text strings together
660
to form a bigger image. Then you can use this image with widgets that
661
support the -image option. For example, you can display a text string string
662
together with a bitmap, at the same time, inside a TK button widget.
664
list.pack(expand=1, fill=tkinter.tix.BOTH, padx=4, pady=6)
665
text.pack(expand=1, fill=tkinter.tix.BOTH, padx=4, pady=6)
667
msg.pack(side=tkinter.tix.TOP, padx=3, pady=3, fill=tkinter.tix.BOTH)
668
group.pack(side=tkinter.tix.TOP, padx=3, pady=3, fill=tkinter.tix.BOTH)
669
pane.pack(side=tkinter.tix.TOP, padx=3, pady=3, fill=tkinter.tix.BOTH, expand=1)
672
msg = tkinter.tix.Message(w,
673
relief=tkinter.tix.FLAT, width=240, anchor=tkinter.tix.N,
674
text='The NoteBook widget allows you to layout a complex interface into individual pages.')
675
# prefix = Tix.OptionName(w)
676
# if not prefix: prefix = ''
677
# w.option_add('*' + prefix + '*TixNoteBook*tagPadX', 8)
678
options = "entry.width %d label.width %d label.anchor %s" % (10, 18, tkinter.tix.E)
680
nb = tkinter.tix.NoteBook(w, ipadx=6, ipady=6, options=options)
681
nb.add('hard_disk', label="Hard Disk", underline=0)
682
nb.add('network', label="Network", underline=0)
684
# Frame for the buttons that are present on all pages
685
common = tkinter.tix.Frame(nb.hard_disk)
686
common.pack(side=tkinter.tix.RIGHT, padx=2, pady=2, fill=tkinter.tix.Y)
687
CreateCommonButtons(common)
689
# Widgets belonging only to this page
690
a = tkinter.tix.Control(nb.hard_disk, value=12, label='Access Time: ')
691
w = tkinter.tix.Control(nb.hard_disk, value=400, label='Write Throughput: ')
692
r = tkinter.tix.Control(nb.hard_disk, value=400, label='Read Throughput: ')
693
c = tkinter.tix.Control(nb.hard_disk, value=1021, label='Capacity: ')
694
a.pack(side=tkinter.tix.TOP, padx=20, pady=2)
695
w.pack(side=tkinter.tix.TOP, padx=20, pady=2)
696
r.pack(side=tkinter.tix.TOP, padx=20, pady=2)
697
c.pack(side=tkinter.tix.TOP, padx=20, pady=2)
699
common = tkinter.tix.Frame(nb.network)
700
common.pack(side=tkinter.tix.RIGHT, padx=2, pady=2, fill=tkinter.tix.Y)
701
CreateCommonButtons(common)
703
a = tkinter.tix.Control(nb.network, value=12, label='Access Time: ')
704
w = tkinter.tix.Control(nb.network, value=400, label='Write Throughput: ')
705
r = tkinter.tix.Control(nb.network, value=400, label='Read Throughput: ')
706
c = tkinter.tix.Control(nb.network, value=1021, label='Capacity: ')
707
u = tkinter.tix.Control(nb.network, value=10, label='Users: ')
708
a.pack(side=tkinter.tix.TOP, padx=20, pady=2)
709
w.pack(side=tkinter.tix.TOP, padx=20, pady=2)
710
r.pack(side=tkinter.tix.TOP, padx=20, pady=2)
711
c.pack(side=tkinter.tix.TOP, padx=20, pady=2)
712
u.pack(side=tkinter.tix.TOP, padx=20, pady=2)
714
msg.pack(side=tkinter.tix.TOP, padx=3, pady=3, fill=tkinter.tix.BOTH)
715
nb.pack(side=tkinter.tix.TOP, padx=5, pady=5, fill=tkinter.tix.BOTH, expand=1)
717
def CreateCommonButtons(f):
718
ok = tkinter.tix.Button(f, text='OK', width = 6)
719
cancel = tkinter.tix.Button(f, text='Cancel', width = 6)
720
ok.pack(side=tkinter.tix.TOP, padx=2, pady=2)
721
cancel.pack(side=tkinter.tix.TOP, padx=2, pady=2)
723
def MkDirList(nb, name):
725
options = "label.padX 4"
727
dir = tkinter.tix.LabelFrame(w, label='Tix.DirList', options=options)
728
fsbox = tkinter.tix.LabelFrame(w, label='Tix.ExFileSelectBox', options=options)
729
MkDirListWidget(dir.frame)
730
MkExFileWidget(fsbox.frame)
731
dir.form(top=0, left=0, right='%40', bottom=-1)
732
fsbox.form(top=0, left='%40', right=-1, bottom=-1)
734
def MkDirListWidget(w):
735
"""The TixDirList widget gives a graphical representation of the file
736
system directory and makes it easy for the user to choose and access
739
msg = tkinter.tix.Message(w,
740
relief=tkinter.tix.FLAT, width=240, anchor=tkinter.tix.N,
741
text='The Tix DirList widget gives a graphical representation of the file system directory and makes it easy for the user to choose and access directories.')
742
dirlist = tkinter.tix.DirList(w, options='hlist.padY 1 hlist.width 25 hlist.height 16')
743
msg.pack(side=tkinter.tix.TOP, expand=1, fill=tkinter.tix.BOTH, padx=3, pady=3)
744
dirlist.pack(side=tkinter.tix.TOP, padx=3, pady=3)
746
def MkExFileWidget(w):
747
"""The TixExFileSelectBox widget is more user friendly than the Motif
748
style FileSelectBox. """
749
msg = tkinter.tix.Message(w,
750
relief=tkinter.tix.FLAT, width=240, anchor=tkinter.tix.N,
751
text='The Tix ExFileSelectBox widget is more user friendly than the Motif style FileSelectBox.')
752
# There's a bug in the ComboBoxes - the scrolledlistbox is destroyed
753
box = tkinter.tix.ExFileSelectBox(w, bd=2, relief=tkinter.tix.RAISED)
754
msg.pack(side=tkinter.tix.TOP, expand=1, fill=tkinter.tix.BOTH, padx=3, pady=3)
755
box.pack(side=tkinter.tix.TOP, padx=3, pady=3)
758
### List of all the demos we want to show off
759
comments = {'widget' : 'Widget Demos', 'image' : 'Image Demos'}
760
samples = {'Balloon' : 'Balloon',
761
'Button Box' : 'BtnBox',
762
'Combo Box' : 'ComboBox',
763
'Compound Image' : 'CmpImg',
764
'Directory List' : 'DirList',
765
'Directory Tree' : 'DirTree',
766
'Control' : 'Control',
767
'Notebook' : 'NoteBook',
768
'Option Menu' : 'OptMenu',
769
'Paned Window' : 'PanedWin',
770
'Popup Menu' : 'PopMenu',
771
'ScrolledHList (1)' : 'SHList1',
772
'ScrolledHList (2)' : 'SHList2',
773
'Tree (dynamic)' : 'Tree'
776
# There are still a lot of demos to be translated:
778
## {d "File Selectors" file }
779
## {d "Hierachical ListBox" hlist }
780
## {d "Tabular ListBox" tlist {c tixTList}}
781
## {d "Grid Widget" grid {c tixGrid}}
782
## {d "Manager Widgets" manager }
783
## {d "Scrolled Widgets" scroll }
784
## {d "Miscellaneous Widgets" misc }
785
## {d "Image Types" image }
789
## {d "Compound Image" cmpimg }
790
## {d "XPM Image" xpm {i pixmap}}
794
##done {f "In Buttons" CmpImg.tcl }
795
## {f "In NoteBook" CmpImg2.tcl }
796
## {f "Notebook Color Tabs" CmpImg4.tcl }
797
## {f "Icons" CmpImg3.tcl }
801
## {f "In Button" Xpm.tcl {i pixmap}}
802
## {f "In Menu" Xpm1.tcl {i pixmap}}
806
##added {f DirList DirList.tcl }
807
##added {f DirTree DirTree.tcl }
808
## {f DirSelectDialog DirDlg.tcl }
809
## {f ExFileSelectDialog EFileDlg.tcl }
810
## {f FileSelectDialog FileDlg.tcl }
811
## {f FileEntry FileEnt.tcl }
815
## {f HList HList1.tcl }
816
## {f CheckList ChkList.tcl {c tixCheckList}}
817
##done {f "ScrolledHList (1)" SHList.tcl }
818
##done {f "ScrolledHList (2)" SHList2.tcl }
819
##done {f Tree Tree.tcl }
820
##done {f "Tree (Dynamic)" DynTree.tcl {v win}}
824
## {f "ScrolledTList (1)" STList1.tcl {c tixTList}}
825
## {f "ScrolledTList (2)" STList2.tcl {c tixTList}}
827
## global tcl_platform
828
## # This demo hangs windows
829
## if {$tcl_platform(platform) != "windows"} {
830
##na lappend tlist {f "TList File Viewer" STList3.tcl {c tixTList}}
834
##na {f "Simple Grid" SGrid0.tcl {c tixGrid}}
835
##na {f "ScrolledGrid" SGrid1.tcl {c tixGrid}}
836
##na {f "Editable Grid" EditGrid.tcl {c tixGrid}}
840
## {f ScrolledListBox SListBox.tcl }
841
## {f ScrolledText SText.tcl }
842
## {f ScrolledWindow SWindow.tcl }
843
##na {f "Canvas Object View" CObjView.tcl {c tixCObjView}}
847
## {f ListNoteBook ListNBK.tcl }
848
##done {f NoteBook NoteBook.tcl }
849
##done {f PanedWindow PanedWin.tcl }
853
##done {f Balloon Balloon.tcl }
854
##done {f ButtonBox BtnBox.tcl }
855
##done {f ComboBox ComboBox.tcl }
856
##done {f Control Control.tcl }
857
## {f LabelEntry LabEntry.tcl }
858
## {f LabelFrame LabFrame.tcl }
859
## {f Meter Meter.tcl {c tixMeter}}
860
##done {f OptionMenu OptMenu.tcl }
861
##done {f PopupMenu PopMenu.tcl }
862
## {f Select Select.tcl }
863
## {f StdButtonBox StdBBox.tcl }
868
stypes['widget'] = ['Balloon', 'Button Box', 'Combo Box', 'Control',
869
'Directory List', 'Directory Tree',
870
'Notebook', 'Option Menu', 'Popup Menu', 'Paned Window',
871
'ScrolledHList (1)', 'ScrolledHList (2)', 'Tree (dynamic)']
872
stypes['image'] = ['Compound Image']
874
def MkSample(nb, name):
876
options = "label.padX 4"
878
pane = tkinter.tix.PanedWindow(w, orientation='horizontal')
879
pane.pack(side=tkinter.tix.TOP, expand=1, fill=tkinter.tix.BOTH)
880
f1 = pane.add('list', expand='1')
881
f2 = pane.add('text', expand='5')
882
f1['relief'] = 'flat'
883
f2['relief'] = 'flat'
885
lab = tkinter.tix.LabelFrame(f1, label='Select a sample program:')
886
lab.pack(side=tkinter.tix.TOP, expand=1, fill=tkinter.tix.BOTH, padx=5, pady=5)
887
lab1 = tkinter.tix.LabelFrame(f2, label='Source:')
888
lab1.pack(side=tkinter.tix.TOP, expand=1, fill=tkinter.tix.BOTH, padx=5, pady=5)
890
slb = tkinter.tix.Tree(lab.frame, options='hlist.width 20')
891
slb.pack(side=tkinter.tix.TOP, expand=1, fill=tkinter.tix.BOTH, padx=5)
893
stext = tkinter.tix.ScrolledText(lab1.frame, name='stext')
894
font = root.tk.eval('tix option get fixed_font')
895
stext.text.config(font=font)
897
frame = tkinter.tix.Frame(lab1.frame, name='frame')
899
run = tkinter.tix.Button(frame, text='Run ...', name='run')
900
view = tkinter.tix.Button(frame, text='View Source ...', name='view')
901
run.pack(side=tkinter.tix.LEFT, expand=0, fill=tkinter.tix.NONE)
902
view.pack(side=tkinter.tix.LEFT, expand=0, fill=tkinter.tix.NONE)
904
stext.text['bg'] = slb.hlist['bg']
905
stext.text['state'] = 'disabled'
906
stext.text['wrap'] = 'none'
907
stext.text['width'] = 80
909
frame.pack(side=tkinter.tix.BOTTOM, expand=0, fill=tkinter.tix.X, padx=7)
910
stext.pack(side=tkinter.tix.TOP, expand=0, fill=tkinter.tix.BOTH, padx=7)
912
slb.hlist['separator'] = '.'
913
slb.hlist['width'] = 25
914
slb.hlist['drawbranch'] = 0
915
slb.hlist['indent'] = 10
916
slb.hlist['wideselect'] = 1
917
slb.hlist['command'] = lambda args=0, w=w,slb=slb,stext=stext,run=run,view=view: Sample_Action(w, slb, stext, run, view, 'run')
918
slb.hlist['browsecmd'] = lambda args=0, w=w,slb=slb,stext=stext,run=run,view=view: Sample_Action(w, slb, stext, run, view, 'browse')
920
run['command'] = lambda args=0, w=w,slb=slb,stext=stext,run=run,view=view: Sample_Action(w, slb, stext, run, view, 'run')
921
view['command'] = lambda args=0, w=w,slb=slb,stext=stext,run=run,view=view: Sample_Action(w, slb, stext, run, view, 'view')
923
for type in ['widget', 'image']:
925
x = tkinter.tix.Frame(slb.hlist, bd=2, height=2, width=150,
926
relief=tkinter.tix.SUNKEN, bg=slb.hlist['bg'])
927
slb.hlist.add_child(itemtype=tkinter.tix.WINDOW, window=x, state='disabled')
928
x = slb.hlist.add_child(itemtype=tkinter.tix.TEXT, state='disabled',
930
for key in stypes[type]:
931
slb.hlist.add_child(x, itemtype=tkinter.tix.TEXT, data=key,
933
slb.hlist.selection_clear()
935
run['state'] = 'disabled'
936
view['state'] = 'disabled'
938
def Sample_Action(w, slb, stext, run, view, action):
942
anchor = hlist.info_anchor()
944
run['state'] = 'disabled'
945
view['state'] = 'disabled'
946
elif not hlist.info_parent(anchor):
950
run['state'] = 'normal'
951
view['state'] = 'normal'
952
key = hlist.info_data(anchor)
957
exec('import ' + prog)
958
w = tkinter.tix.Toplevel()
960
rtn = eval(prog + '.RunSample')
962
elif action == 'view':
963
w = tkinter.tix.Toplevel()
964
w.title('Source view: ' + title)
965
LoadFile(w, demo.dir + '/samples/' + prog + '.py')
966
elif action == 'browse':
967
ReadFile(stext.text, demo.dir + '/samples/' + prog + '.py')
969
def LoadFile(w, fname):
971
b = tkinter.tix.Button(w, text='Close', command=w.destroy)
972
t = tkinter.tix.ScrolledText(w)
973
# b.form(left=0, bottom=0, padx=4, pady=4)
974
# t.form(left=0, bottom=b, right='-0', top=0)
978
font = root.tk.eval('tix option get fixed_font')
979
t.text.config(font=font)
981
t.text['wrap'] = 'none'
983
ReadFile(t.text, fname)
985
def ReadFile(w, fname):
986
old_state = w['state']
987
w['state'] = 'normal'
988
w.delete('0.0', tkinter.tix.END)
992
lines = f.readlines()
994
w.insert(tkinter.tix.END, s)
998
w['state'] = old_state
1000
if __name__ == '__main__':
1001
root = tkinter.tix.Tk()