1 # Tkinter.py -- Tk/Tcl widget wrappers
4 from tkinter
import TclError
12 FunctionType
= type(_func
)
13 ClassType
= type(_Dummy
)
14 MethodType
= type(_Dummy
.meth
)
18 DictionaryType
= type({})
20 CallableTypes
= (FunctionType
, MethodType
)
25 if type(item
) in (TupleType
, ListType
):
26 res
= res
+ _flatten(item
)
32 if type(cnfs
) in (NoneType
, DictionaryType
, StringType
):
36 for c
in _flatten(cnfs
):
37 for k
, v
in c
.items():
51 sys
.exit(getint(code
))
55 def __init__(self
, master
=None):
61 self
._tk
= _default_root
.tk
62 self
._name
= 'PY_VAR' + `_varnum`
65 self
._tk
.unsetvar(self
._name
)
68 def __call__(self
, value
=None):
74 return self
._tk
.setvar(self
._name
, value
)
76 class StringVar(Variable
):
77 def __init__(self
, master
=None):
78 Variable
.__init
__(self
, master
)
80 return self
._tk
.getvar(self
._name
)
82 class IntVar(Variable
):
83 def __init__(self
, master
=None):
84 Variable
.__init
__(self
, master
)
86 return self
._tk
.getint(self
._tk
.getvar(self
._name
))
88 class DoubleVar(Variable
):
89 def __init__(self
, master
=None):
90 Variable
.__init
__(self
, master
)
92 return self
._tk
.getdouble(self
._tk
.getvar(self
._name
))
94 class BooleanVar(Variable
):
95 def __init__(self
, master
=None):
96 Variable
.__init
__(self
, master
)
98 return self
._tk
.getboolean(self
._tk
.getvar(self
._name
))
101 _default_root
.tk
.mainloop()
104 return _default_root
.tk
.getint(s
)
107 return _default_root
.tk
.getdouble(s
)
110 return _default_root
.tk
.getboolean(s
)
113 def tk_strictMotif(self
, boolean
=None):
114 return self
.tk
.getboolean(self
.tk
.call(
115 'set', 'tk_strictMotif', boolean
))
116 def tk_menuBar(self
, *args
):
117 apply(self
.tk
.call
, ('tk_menuBar', self
._w
) + args
)
118 def wait_variable(self
, name
='PY_VAR'):
119 self
.tk
.call('tkwait', 'variable', name
)
120 waitvar
= wait_variable
# XXX b/w compat
121 def wait_window(self
, window
=None):
124 self
.tk
.call('tkwait', 'window', window
._w
)
125 def wait_visibility(self
, window
=None):
128 self
.tk
.call('tkwait', 'visibility', window
._w
)
129 def setvar(self
, name
='PY_VAR', value
='1'):
130 self
.tk
.setvar(name
, value
)
131 def getvar(self
, name
='PY_VAR'):
132 return self
.tk
.getvar(name
)
134 return self
.tk
.getint(s
)
135 def getdouble(self
, s
):
136 return self
.tk
.getdouble(s
)
137 def getboolean(self
, s
):
138 return self
.tk
.getboolean(s
)
140 self
.tk
.call('focus', self
._w
)
141 focus
= focus_set
# XXX b/w compat?
142 def focus_default_set(self
):
143 self
.tk
.call('focus', 'default', self
._w
)
144 def focus_default_none(self
):
145 self
.tk
.call('focus', 'default', 'none')
146 focus_default
= focus_default_set
147 def focus_none(self
):
148 self
.tk
.call('focus', 'none')
150 name
= self
.tk
.call('focus')
151 if name
== 'none': return None
152 return self
._nametowidget
(name
)
153 def after(self
, ms
, func
=None, *args
):
155 self
.tk
.call('after', ms
)
157 # XXX Disgusting hack to clean up after calling func
159 def callit(func
=func
, args
=args
, tk
=self
.tk
, tmp
=tmp
):
163 tk
.deletecommand(tmp
[0])
164 name
= self
._register
(callit
)
166 self
.tk
.call('after', ms
, name
)
167 # XXX grab current w/o window argument
168 def grab_current(self
):
169 name
= self
.tk
.call('grab', 'current', self
._w
)
170 if not name
: return None
171 return self
._nametowidget
(name
)
172 def grab_release(self
):
173 self
.tk
.call('grab', 'release', self
._w
)
175 self
.tk
.call('grab', 'set', self
._w
)
176 def grab_set_global(self
):
177 self
.tk
.call('grab', 'set', '-global', self
._w
)
178 def grab_status(self
):
179 status
= self
.tk
.call('grab', 'status', self
._w
)
180 if status
== 'none': status
= None
182 def lower(self
, belowThis
=None):
183 self
.tk
.call('lower', self
._w
, belowThis
)
184 def option_add(self
, pattern
, value
, priority
= None):
185 self
.tk
.call('option', 'add', pattern
, priority
)
186 def option_clear(self
):
187 self
.tk
.call('option', 'clear')
188 def option_get(self
, name
, className
):
189 return self
.tk
.call('option', 'get', self
._w
, name
, className
)
190 def option_readfile(self
, fileName
, priority
= None):
191 self
.tk
.call('option', 'readfile', fileName
, priority
)
192 def selection_clear(self
):
193 self
.tk
.call('selection', 'clear', self
._w
)
194 def selection_get(self
, type=None):
195 return self
.tk
.call('selection', 'get', type)
196 def selection_handle(self
, func
, type=None, format
=None):
197 name
= self
._register
(func
)
198 self
.tk
.call('selection', 'handle', self
._w
,
200 def selection_own(self
, func
=None):
201 name
= self
._register
(func
)
202 self
.tk
.call('selection', 'own', self
._w
, name
)
203 def selection_own_get(self
):
204 return self
._nametowidget
(self
.tk
.call('selection', 'own'))
205 def send(self
, interp
, cmd
, *args
):
206 return apply(self
.tk
.call
, ('send', interp
, cmd
) + args
)
207 def lower(self
, belowThis
=None):
208 self
.tk
.call('lift', self
._w
, belowThis
)
209 def tkraise(self
, aboveThis
=None):
210 self
.tk
.call('raise', self
._w
, aboveThis
)
212 def colormodel(self
, value
=None):
213 return self
.tk
.call('tk', 'colormodel', self
._w
, value
)
214 def winfo_atom(self
, name
):
215 return self
.tk
.getint(self
.tk
.call('winfo', 'atom', name
))
216 def winfo_atomname(self
, id):
217 return self
.tk
.call('winfo', 'atomname', id)
218 def winfo_cells(self
):
219 return self
.tk
.getint(
220 self
.tk
.call('winfo', 'cells', self
._w
))
221 def winfo_children(self
):
222 return map(self
._nametowidget
,
223 self
.tk
.splitlist(self
.tk
.call(
224 'winfo', 'children', self
._w
)))
225 def winfo_class(self
):
226 return self
.tk
.call('winfo', 'class', self
._w
)
227 def winfo_containing(self
, rootX
, rootY
):
228 return self
.tk
.call('winfo', 'containing', rootx
, rootY
)
229 def winfo_depth(self
):
230 return self
.tk
.getint(self
.tk
.call('winfo', 'depth', self
._w
))
231 def winfo_exists(self
):
232 return self
.tk
.getint(
233 self
.tk
.call('winfo', 'exists', self
._w
))
234 def winfo_fpixels(self
, number
):
235 return self
.tk
.getdouble(self
.tk
.call(
236 'winfo', 'fpixels', self
._w
, number
))
237 def winfo_geometry(self
):
238 return self
.tk
.call('winfo', 'geometry', self
._w
)
239 def winfo_height(self
):
240 return self
.tk
.getint(
241 self
.tk
.call('winfo', 'height', self
._w
))
243 return self
.tk
.getint(
244 self
.tk
.call('winfo', 'id', self
._w
))
245 def winfo_interps(self
):
246 return self
.tk
.splitlist(
247 self
.tk
.call('winfo', 'interps'))
248 def winfo_ismapped(self
):
249 return self
.tk
.getint(
250 self
.tk
.call('winfo', 'ismapped', self
._w
))
251 def winfo_name(self
):
252 return self
.tk
.call('winfo', 'name', self
._w
)
253 def winfo_parent(self
):
254 return self
.tk
.call('winfo', 'parent', self
._w
)
255 def winfo_pathname(self
, id):
256 return self
.tk
.call('winfo', 'pathname', id)
257 def winfo_pixels(self
, number
):
258 return self
.tk
.getint(
259 self
.tk
.call('winfo', 'pixels', self
._w
, number
))
260 def winfo_reqheight(self
):
261 return self
.tk
.getint(
262 self
.tk
.call('winfo', 'reqheight', self
._w
))
263 def winfo_reqwidth(self
):
264 return self
.tk
.getint(
265 self
.tk
.call('winfo', 'reqwidth', self
._w
))
266 def winfo_rgb(self
, color
):
267 return self
._getints
(
268 self
.tk
.call('winfo', 'rgb', self
._w
, color
))
269 def winfo_rootx(self
):
270 return self
.tk
.getint(
271 self
.tk
.call('winfo', 'rootx', self
._w
))
272 def winfo_rooty(self
):
273 return self
.tk
.getint(
274 self
.tk
.call('winfo', 'rooty', self
._w
))
275 def winfo_screen(self
):
276 return self
.tk
.call('winfo', 'screen', self
._w
)
277 def winfo_screencells(self
):
278 return self
.tk
.getint(
279 self
.tk
.call('winfo', 'screencells', self
._w
))
280 def winfo_screendepth(self
):
281 return self
.tk
.getint(
282 self
.tk
.call('winfo', 'screendepth', self
._w
))
283 def winfo_screenheight(self
):
284 return self
.tk
.getint(
285 self
.tk
.call('winfo', 'screenheight', self
._w
))
286 def winfo_screenmmheight(self
):
287 return self
.tk
.getint(
288 self
.tk
.call('winfo', 'screenmmheight', self
._w
))
289 def winfo_screenmmwidth(self
):
290 return self
.tk
.getint(
291 self
.tk
.call('winfo', 'screenmmwidth', self
._w
))
292 def winfo_screenvisual(self
):
293 return self
.tk
.call('winfo', 'screenvisual', self
._w
)
294 def winfo_screenwidth(self
):
295 return self
.tk
.getint(
296 self
.tk
.call('winfo', 'screenwidth', self
._w
))
297 def winfo_toplevel(self
):
298 return self
._nametowidget
(self
.tk
.call(
299 'winfo', 'toplevel', self
._w
))
300 def winfo_visual(self
):
301 return self
.tk
.call('winfo', 'visual', self
._w
)
302 def winfo_vrootheight(self
):
303 return self
.tk
.getint(
304 self
.tk
.call('winfo', 'vrootheight', self
._w
))
305 def winfo_vrootwidth(self
):
306 return self
.tk
.getint(
307 self
.tk
.call('winfo', 'vrootwidth', self
._w
))
308 def winfo_vrootx(self
):
309 return self
.tk
.getint(
310 self
.tk
.call('winfo', 'vrootx', self
._w
))
311 def winfo_vrooty(self
):
312 return self
.tk
.getint(
313 self
.tk
.call('winfo', 'vrooty', self
._w
))
314 def winfo_width(self
):
315 return self
.tk
.getint(
316 self
.tk
.call('winfo', 'width', self
._w
))
318 return self
.tk
.getint(
319 self
.tk
.call('winfo', 'x', self
._w
))
321 return self
.tk
.getint(
322 self
.tk
.call('winfo', 'y', self
._w
))
324 self
.tk
.call('update')
325 def update_idletasks(self
):
326 self
.tk
.call('update', 'idletasks')
327 def unbind(self
, sequence
):
328 self
.tk
.call('bind', self
._w
, sequence
, '')
329 def bind(self
, sequence
, func
, add
=''):
331 name
= self
._register
(func
, self
._substitute
)
332 self
.tk
.call('bind', self
._w
, sequence
,
333 (add
+ name
,) + self
._subst
_format
)
334 def bind_all(self
, sequence
, func
, add
=''):
336 name
= self
._register
(func
, self
._substitute
)
337 self
.tk
.call('bind', 'all' , sequence
,
338 (add
+ name
,) + self
._subst
_format
)
339 def bind_class(self
, className
, sequence
, func
, add
=''):
341 name
= self
._register
(func
, self
._substitute
)
342 self
.tk
.call('bind', className
, sequence
,
343 (add
+ name
,) + self
._subst
_format
)
348 def _getints(self
, string
):
349 if not string
: return None
351 for v
in self
.tk
.splitlist(string
):
352 res
= res
+ (self
.tk
.getint(v
),)
354 def _getboolean(self
, string
):
356 return self
.tk
.getboolean(string
)
357 def _options(self
, cnf
):
360 for k
, v
in cnf
.items():
361 if type(v
) in CallableTypes
:
362 v
= self
._register
(v
)
363 res
= res
+ ('-'+k
, v
)
365 def _nametowidget(self
, name
):
370 from string
import find
374 name
, tail
= name
[:i
], name
[i
+1:]
380 def _register(self
, func
, subst
=None):
381 f
= _CallSafely(func
, subst
).__call
__
383 if hasattr(func
, 'im_func'):
385 if hasattr(func
, 'func_name') and \
386 type(func
.func_name
) == type(''):
387 name
= name
+ func
.func_name
388 self
.tk
.createcommand(name
, f
)
393 while w
.master
: w
= w
.master
395 _subst_format
= ('%#', '%b', '%f', '%h', '%k',
396 '%s', '%t', '%w', '%x', '%y',
397 '%A', '%E', '%K', '%N', '%W', '%T', '%X', '%Y')
398 def _substitute(self
, *args
):
400 if len(args
) != len(self
._subst
_format
): return args
401 nsign
, b
, f
, h
, k
, s
, t
, w
, x
, y
, A
, E
, K
, N
, W
, T
, X
, Y
= args
402 # Missing: (a, c, d, m, o, v, B, R)
404 e
.serial
= tk
.getint(nsign
)
406 try: e
.focus
= tk
.getboolean(f
)
407 except TclError
: pass
408 e
.height
= tk
.getint(h
)
409 e
.keycode
= tk
.getint(k
)
410 e
.state
= tk
.getint(s
)
411 e
.time
= tk
.getint(t
)
412 e
.width
= tk
.getint(w
)
416 try: e
.send_event
= tk
.getboolean(E
)
417 except TclError
: pass
419 e
.keysym_num
= tk
.getint(N
)
421 e
.widget
= self
._nametowidget
(W
)
422 e
.x_root
= tk
.getint(X
)
423 e
.y_root
= tk
.getint(Y
)
427 def __init__(self
, func
, subst
=None):
430 def __call__(self
, *args
):
432 args
= self
.apply_func(self
.subst
, args
)
433 args
= self
.apply_func(self
.func
, args
)
434 def apply_func(self
, func
, args
):
437 return apply(func
, args
)
438 except SystemExit, msg
:
439 raise SystemExit, msg
443 t
= sys
.exc_traceback
451 sys
.stderr
.write('%s: %s\n' %
456 sys
.last_traceback
) = (sys
.exc_type
,
462 print '*** Error in error handling ***'
463 print sys
.exc_type
, ':', sys
.exc_value
467 minNumer
=None, minDenom
=None,
468 maxNumer
=None, maxDenom
=None):
469 return self
._getints
(
470 self
.tk
.call('wm', 'aspect', self
._w
,
473 def client(self
, name
=None):
474 return self
.tk
.call('wm', 'client', self
._w
, name
)
475 def command(self
, value
=None):
476 return self
.tk
.call('wm', 'command', self
._w
, value
)
478 return self
.tk
.call('wm', 'deiconify', self
._w
)
479 def focusmodel(self
, model
=None):
480 return self
.tk
.call('wm', 'focusmodel', self
._w
, model
)
482 return self
.tk
.call('wm', 'frame', self
._w
)
483 def geometry(self
, newGeometry
=None):
484 return self
.tk
.call('wm', 'geometry', self
._w
, newGeometry
)
486 baseWidht
=None, baseHeight
=None,
487 widthInc
=None, heightInc
=None):
488 return self
._getints
(self
.tk
.call(
489 'wm', 'grid', self
._w
,
490 baseWidht
, baseHeight
, widthInc
, heightInc
))
491 def group(self
, pathName
=None):
492 return self
.tk
.call('wm', 'group', self
._w
, pathName
)
493 def iconbitmap(self
, bitmap
=None):
494 return self
.tk
.call('wm', 'iconbitmap', self
._w
, bitmap
)
496 return self
.tk
.call('wm', 'iconify', self
._w
)
497 def iconmask(self
, bitmap
=None):
498 return self
.tk
.call('wm', 'iconmask', self
._w
, bitmap
)
499 def iconname(self
, newName
=None):
500 return self
.tk
.call('wm', 'iconname', self
._w
, newName
)
501 def iconposition(self
, x
=None, y
=None):
502 return self
._getints
(self
.tk
.call(
503 'wm', 'iconposition', self
._w
, x
, y
))
504 def iconwindow(self
, pathName
=None):
505 return self
.tk
.call('wm', 'iconwindow', self
._w
, pathName
)
506 def maxsize(self
, width
=None, height
=None):
507 return self
._getints
(self
.tk
.call(
508 'wm', 'maxsize', self
._w
, width
, height
))
509 def minsize(self
, width
=None, height
=None):
510 return self
._getints
(self
.tk
.call(
511 'wm', 'minsize', self
._w
, width
, height
))
512 def overrideredirect(self
, boolean
=None):
513 return self
._getboolean
(self
.tk
.call(
514 'wm', 'overrideredirect', self
._w
, boolean
))
515 def positionfrom(self
, who
=None):
516 return self
.tk
.call('wm', 'positionfrom', self
._w
, who
)
517 def protocol(self
, name
=None, func
=None):
518 if type(func
) in CallableTypes
:
519 command
= self
._register
(func
)
523 'wm', 'protocol', self
._w
, name
, command
)
524 def sizefrom(self
, who
=None):
525 return self
.tk
.call('wm', 'sizefrom', self
._w
, who
)
527 return self
.tk
.call('wm', 'state', self
._w
)
528 def title(self
, string
=None):
529 return self
.tk
.call('wm', 'title', self
._w
, string
)
530 def transient(self
, master
=None):
531 return self
.tk
.call('wm', 'transient', self
._w
, master
)
533 return self
.tk
.call('wm', 'withdraw', self
._w
)
537 def __init__(self
, screenName
=None, baseName
=None, className
='Tk'):
542 baseName
= os
.path
.basename(sys
.argv
[0])
543 if baseName
[-3:] == '.py': baseName
= baseName
[:-3]
544 self
.tk
= tkinter
.create(screenName
, baseName
, className
)
545 self
.tk
.createcommand('tkerror', _tkerror
)
546 self
.tk
.createcommand('exit', _exit
)
547 self
.readprofile(baseName
, className
)
549 for c
in self
.children
.values(): c
.destroy()
550 self
.tk
.call('destroy', self
._w
)
553 def readprofile(self
, baseName
, className
):
555 if os
.environ
.has_key('HOME'): home
= os
.environ
['HOME']
556 else: home
= os
.curdir
557 class_tcl
= os
.path
.join(home
, '.%s.tcl' % className
)
558 class_py
= os
.path
.join(home
, '.%s.py' % className
)
559 base_tcl
= os
.path
.join(home
, '.%s.tcl' % baseName
)
560 base_py
= os
.path
.join(home
, '.%s.py' % baseName
)
562 exec 'from Tkinter import *' in dir
563 if os
.path
.isfile(class_tcl
):
564 print 'source', `class_tcl`
565 self
.tk
.call('source', class_tcl
)
566 if os
.path
.isfile(class_py
):
567 print 'execfile', `class_py`
568 execfile(class_py
, dir)
569 if os
.path
.isfile(base_tcl
):
570 print 'source', `base_tcl`
571 self
.tk
.call('source', base_tcl
)
572 if os
.path
.isfile(base_py
):
573 print 'execfile', `base_py`
574 execfile(base_py
, dir)
577 def config(self
, cnf
={}):
579 ('pack', 'configure', self
._w
)
580 + self
._options
(cnf
))
582 def __setitem__(self
, key
, value
):
583 Pack
.config({key
: value
})
585 self
.tk
.call('pack', 'forget', self
._w
)
587 words
= self
.tk
.splitlist(
588 self
.tk
.call('pack', 'newinfo', self
._w
))
590 for i
in range(0, len(words
), 2):
594 value
= self
._nametowidget
(value
)
598 _noarg_
= ['_noarg_']
599 def propagate(self
, flag
=_noarg_
):
600 if boolean
is Pack
._noarg
_:
601 return self
._getboolean
(self
.tk
.call(
602 'pack', 'propagate', self
._w
))
604 self
.tk
.call('pack', 'propagate', self
._w
, flag
)
606 return map(self
._nametowidget
,
608 self
.tk
.call('pack', 'slaves', self
._w
)))
611 def config(self
, cnf
={}):
613 ('place', 'configure', self
._w
)
614 + self
._options
(cnf
))
616 def __setitem__(self
, key
, value
):
617 Place
.config({key
: value
})
619 self
.tk
.call('place', 'forget', self
._w
)
621 return self
.tk
.call('place', 'info', self
._w
)
623 return map(self
._nametowidget
,
626 'place', 'slaves', self
._w
)))
628 class Widget(Misc
, Pack
, Place
):
629 def _setup(self
, master
, cnf
):
632 if not _default_root
:
634 master
= _default_root
635 if not _default_root
:
636 _default_root
= master
639 if cnf
.has_key('name'):
648 self
._w
= master
._w
+ '.' + name
650 if self
.master
.children
.has_key(self
._name
):
651 self
.master
.children
[self
._name
].destroy()
652 self
.master
.children
[self
._name
] = self
653 def __init__(self
, master
, widgetName
, cnf
={}, extra
=()):
655 Widget
._setup
(self
, master
, cnf
)
656 self
.widgetName
= widgetName
657 apply(self
.tk
.call
, (widgetName
, self
._w
) + extra
)
659 Widget
.config(self
, cnf
)
660 def config(self
, cnf
=None):
664 for x
in self
.tk
.split(
665 self
.tk
.call(self
._w
, 'configure')):
666 cnf
[x
[0][1:]] = (x
[0][1:],) + x
[1:]
668 if type(cnf
) == StringType
:
669 x
= self
.tk
.split(self
.tk
.call(
670 self
._w
, 'configure', '-'+cnf
))
671 return (x
[0][1:],) + x
[1:]
673 if type(k
) == ClassType
:
674 k
.config(self
, cnf
[k
])
676 apply(self
.tk
.call
, (self
._w
, 'configure')
677 + self
._options
(cnf
))
678 def __getitem__(self
, key
):
679 v
= self
.tk
.splitlist(self
.tk
.call(
680 self
._w
, 'configure', '-' + key
))
682 def __setitem__(self
, key
, value
):
683 Widget
.config(self
, {key
: value
})
685 return map(lambda x
: x
[0][1:],
686 self
.tk
.split(self
.tk
.call(self
._w
, 'configure')))
690 for c
in self
.children
.values(): c
.destroy()
691 if self
.master
.children
.has_key(self
._name
):
692 del self
.master
.children
[self
._name
]
693 self
.tk
.call('destroy', self
._w
)
694 def _do(self
, name
, args
=()):
695 return apply(self
.tk
.call
, (self
._w
, name
) + args
)
697 class Toplevel(Widget
, Wm
):
698 def __init__(self
, master
=None, cnf
={}):
700 if cnf
.has_key('screen'):
701 extra
= ('-screen', cnf
['screen'])
703 if cnf
.has_key('class'):
704 extra
= extra
+ ('-class', cnf
['class'])
706 Widget
.__init
__(self
, master
, 'toplevel', cnf
, extra
)
708 self
.iconname(root
.iconname())
709 self
.title(root
.title())
711 class Button(Widget
):
712 def __init__(self
, master
=None, cnf
={}):
713 Widget
.__init
__(self
, master
, 'button', cnf
)
714 def tk_butEnter(self
, *dummy
):
715 self
.tk
.call('tk_butEnter', self
._w
)
716 def tk_butLeave(self
, *dummy
):
717 self
.tk
.call('tk_butLeave', self
._w
)
718 def tk_butDown(self
, *dummy
):
719 self
.tk
.call('tk_butDown', self
._w
)
720 def tk_butUp(self
, *dummy
):
721 self
.tk
.call('tk_butUp', self
._w
)
723 self
.tk
.call(self
._w
, 'flash')
725 self
.tk
.call(self
._w
, 'invoke')
733 if a
: s
= s
+ (' ' + a
)
743 return '@' + `x`
+ ',' + `y`
745 class Canvas(Widget
):
746 def __init__(self
, master
=None, cnf
={}):
747 Widget
.__init
__(self
, master
, 'canvas', cnf
)
748 def addtag(self
, *args
):
749 self
._do
('addtag', args
)
750 def addtag_above(self
, tagOrId
):
751 self
.addtag('above', tagOrId
)
752 def addtag_all(self
):
754 def addtag_below(self
, tagOrId
):
755 self
.addtag('below', tagOrId
)
756 def addtag_closest(self
, x
, y
, halo
=None, start
=None):
757 self
.addtag('closest', x
, y
, halo
, start
)
758 def addtag_enclosed(self
, x1
, y1
, x2
, y2
):
759 self
.addtag('enclosed', x1
, y1
, x2
, y2
)
760 def addtag_overlapping(self
, x1
, y1
, x2
, y2
):
761 self
.addtag('overlapping', x1
, y1
, x2
, y2
)
762 def addtag_withtag(self
, tagOrId
):
763 self
.addtag('withtag', tagOrId
)
764 def bbox(self
, *args
):
765 return self
._getints
(self
._do
('bbox', args
)) or None
766 def tag_unbind(self
, tagOrId
, sequence
):
767 self
.tk
.call(self
._w
, 'bind', tagOrId
, sequence
, '')
768 def tag_bind(self
, tagOrId
, sequence
, func
, add
=''):
770 name
= self
._register
(func
, self
._substitute
)
771 self
.tk
.call(self
._w
, 'bind', tagOrId
, sequence
,
772 (add
+ name
,) + self
._subst
_format
)
773 def canvasx(self
, screenx
, gridspacing
=None):
774 return self
.tk
.getint(self
.tk
.call(
775 self
._w
, 'canvasx', screenx
, gridspacing
))
776 def canvasy(self
, screeny
, gridspacing
=None):
777 return self
.tk
.getint(self
.tk
.call(
778 self
._w
, 'canvasy', screeny
, gridspacing
))
779 def coords(self
, *args
):
780 return self
._do
('coords', args
)
781 def _create(self
, itemType
, args
): # Args: (value, value, ..., cnf={})
782 args
= _flatten(args
)
784 if type(cnf
) in (DictionaryType
, TupleType
):
788 return self
.tk
.getint(apply(
790 (self
._w
, 'create', itemType
)
791 + args
+ self
._options
(cnf
)))
792 def create_arc(self
, *args
):
793 return Canvas
._create
(self
, 'arc', args
)
794 def create_bitmap(self
, *args
):
795 return Canvas
._create
(self
, 'bitmap', args
)
796 def create_line(self
, *args
):
797 return Canvas
._create
(self
, 'line', args
)
798 def create_oval(self
, *args
):
799 return Canvas
._create
(self
, 'oval', args
)
800 def create_polygon(self
, *args
):
801 return Canvas
._create
(self
, 'polygon', args
)
802 def create_rectangle(self
, *args
):
803 return Canvas
._create
(self
, 'rectangle', args
)
804 def create_text(self
, *args
):
805 return Canvas
._create
(self
, 'text', args
)
806 def create_window(self
, *args
):
807 return Canvas
._create
(self
, 'window', args
)
808 def dchars(self
, *args
):
809 self
._do
('dchars', args
)
810 def delete(self
, *args
):
811 self
._do
('delete', args
)
812 def dtag(self
, *args
):
813 self
._do
('dtag', args
)
814 def find(self
, *args
):
815 return self
._getints
(self
._do
('find', args
))
816 def find_above(self
, tagOrId
):
817 return self
.find('above', tagOrId
)
819 return self
.find('all')
820 def find_below(self
, tagOrId
):
821 return self
.find('below', tagOrId
)
822 def find_closest(self
, x
, y
, halo
=None, start
=None):
823 return self
.find('closest', x
, y
, halo
, start
)
824 def find_enclosed(self
, x1
, y1
, x2
, y2
):
825 return self
.find('enclosed', x1
, y1
, x2
, y2
)
826 def find_overlapping(self
, x1
, y1
, x2
, y2
):
827 return self
.find('overlapping', x1
, y1
, x2
, y2
)
828 def find_withtag(self
, tagOrId
):
829 return self
.find('withtag', tagOrId
)
830 def focus(self
, *args
):
831 return self
._do
('focus', args
)
832 def gettags(self
, *args
):
833 return self
.tk
.splitlist(self
._do
('gettags', args
))
834 def icursor(self
, *args
):
835 self
._do
('icursor', args
)
836 def index(self
, *args
):
837 return self
.tk
.getint(self
._do
('index', args
))
838 def insert(self
, *args
):
839 self
._do
('insert', args
)
840 def itemconfig(self
, tagOrId
, cnf
=None):
843 for x
in self
.tk
.split(
844 self
._do
('itemconfigure', (tagOrId
))):
845 cnf
[x
[0][1:]] = (x
[0][1:],) + x
[1:]
847 if type(cnf
) == StringType
:
848 x
= self
.tk
.split(self
._do
('itemconfigure',
849 (tagOrId
, '-'+cnf
,)))
850 return (x
[0][1:],) + x
[1:]
851 self
._do
('itemconfigure', (tagOrId
,) + self
._options
(cnf
))
852 def lower(self
, *args
):
853 self
._do
('lower', args
)
854 def move(self
, *args
):
855 self
._do
('move', args
)
856 def postscript(self
, cnf
={}):
857 return self
._do
('postscript', self
._options
(cnf
))
858 def tkraise(self
, *args
):
859 self
._do
('raise', args
)
861 def scale(self
, *args
):
862 self
._do
('scale', args
)
863 def scan_mark(self
, x
, y
):
864 self
.tk
.call(self
._w
, 'scan', 'mark', x
, y
)
865 def scan_dragto(self
, x
, y
):
866 self
.tk
.call(self
._w
, 'scan', 'dragto', x
, y
)
867 def select_adjust(self
, tagOrId
, index
):
868 self
.tk
.call(self
._w
, 'select', 'adjust', tagOrId
, index
)
869 def select_clear(self
):
870 self
.tk
.call(self
._w
, 'select', 'clear')
871 def select_from(self
, tagOrId
, index
):
872 self
.tk
.call(self
._w
, 'select', 'from', tagOrId
, index
)
873 def select_item(self
):
874 self
.tk
.call(self
._w
, 'select', 'item')
875 def select_to(self
, tagOrId
, index
):
876 self
.tk
.call(self
._w
, 'select', 'to', tagOrId
, index
)
877 def type(self
, tagOrId
):
878 return self
.tk
.call(self
._w
, 'type', tagOrId
) or None
879 def xview(self
, index
):
880 self
.tk
.call(self
._w
, 'xview', index
)
881 def yview(self
, index
):
882 self
.tk
.call(self
._w
, 'yview', index
)
884 class Checkbutton(Widget
):
885 def __init__(self
, master
=None, cnf
={}):
886 Widget
.__init
__(self
, master
, 'checkbutton', cnf
)
888 self
.tk
.call(self
._w
, 'deselect')
890 self
.tk
.call(self
._w
, 'flash')
892 self
.tk
.call(self
._w
, 'invoke')
894 self
.tk
.call(self
._w
, 'select')
896 self
.tk
.call(self
._w
, 'toggle')
899 def __init__(self
, master
=None, cnf
={}):
900 Widget
.__init
__(self
, master
, 'entry', cnf
)
901 def tk_entryBackspace(self
):
902 self
.tk
.call('tk_entryBackspace', self
._w
)
903 def tk_entryBackword(self
):
904 self
.tk
.call('tk_entryBackword', self
._w
)
905 def tk_entrySeeCaret(self
):
906 self
.tk
.call('tk_entrySeeCaret', self
._w
)
907 def delete(self
, first
, last
=None):
908 self
.tk
.call(self
._w
, 'delete', first
, last
)
910 return self
.tk
.call(self
._w
, 'get')
911 def icursor(self
, index
):
912 self
.tk
.call(self
._w
, 'icursor', index
)
913 def index(self
, index
):
914 return self
.tk
.getint(self
.tk
.call(
915 self
._w
, 'index', index
))
916 def insert(self
, index
, string
):
917 self
.tk
.call(self
._w
, 'insert', index
, string
)
918 def scan_mark(self
, x
):
919 self
.tk
.call(self
._w
, 'scan', 'mark', x
)
920 def scan_dragto(self
, x
):
921 self
.tk
.call(self
._w
, 'scan', 'dragto', x
)
922 def select_adjust(self
, index
):
923 self
.tk
.call(self
._w
, 'select', 'adjust', index
)
924 def select_clear(self
):
925 self
.tk
.call(self
._w
, 'select', 'clear')
926 def select_from(self
, index
):
927 self
.tk
.call(self
._w
, 'select', 'from', index
)
928 def select_to(self
, index
):
929 self
.tk
.call(self
._w
, 'select', 'to', index
)
930 def select_view(self
, index
):
931 self
.tk
.call(self
._w
, 'select', 'view', index
)
934 def __init__(self
, master
=None, cnf
={}):
937 if cnf
.has_key('class'):
938 extra
= ('-class', cnf
['class'])
940 Widget
.__init
__(self
, master
, 'frame', cnf
, extra
)
941 def tk_menuBar(self
, *args
):
942 apply(self
.tk
.call
, ('tk_menuBar', self
._w
) + args
)
945 def __init__(self
, master
=None, cnf
={}):
946 Widget
.__init
__(self
, master
, 'label', cnf
)
948 class Listbox(Widget
):
949 def __init__(self
, master
=None, cnf
={}):
950 Widget
.__init
__(self
, master
, 'listbox', cnf
)
951 def tk_listboxSingleSelect(self
):
952 self
.tk
.call('tk_listboxSingleSelect', self
._w
)
953 def curselection(self
):
954 return self
.tk
.splitlist(self
.tk
.call(
955 self
._w
, 'curselection'))
956 def delete(self
, first
, last
=None):
957 self
.tk
.call(self
._w
, 'delete', first
, last
)
958 def get(self
, index
):
959 return self
.tk
.call(self
._w
, 'get', index
)
960 def insert(self
, index
, *elements
):
962 (self
._w
, 'insert', index
) + elements
)
963 def nearest(self
, y
):
964 return self
.tk
.getint(self
.tk
.call(
965 self
._w
, 'nearest', y
))
966 def scan_mark(self
, x
, y
):
967 self
.tk
.call(self
._w
, 'scan', 'mark', x
, y
)
968 def scan_dragto(self
, x
, y
):
969 self
.tk
.call(self
._w
, 'scan', 'dragto', x
, y
)
970 def select_adjust(self
, index
):
971 self
.tk
.call(self
._w
, 'select', 'adjust', index
)
972 def select_clear(self
):
973 self
.tk
.call(self
._w
, 'select', 'clear')
974 def select_from(self
, index
):
975 self
.tk
.call(self
._w
, 'select', 'from', index
)
976 def select_to(self
, index
):
977 self
.tk
.call(self
._w
, 'select', 'to', index
)
979 return self
.tk
.getint(self
.tk
.call(self
._w
, 'size'))
980 def xview(self
, index
):
981 self
.tk
.call(self
._w
, 'xview', index
)
982 def yview(self
, index
):
983 self
.tk
.call(self
._w
, 'yview', index
)
986 def __init__(self
, master
=None, cnf
={}):
987 Widget
.__init
__(self
, master
, 'menu', cnf
)
988 def tk_bindForTraversal(self
):
989 self
.tk
.call('tk_bindForTraversal', self
._w
)
991 self
.tk
.call('tk_mbPost', self
._w
)
992 def tk_mbUnpost(self
):
993 self
.tk
.call('tk_mbUnpost')
994 def tk_traverseToMenu(self
, char
):
995 self
.tk
.call('tk_traverseToMenu', self
._w
, char
)
996 def tk_traverseWithinMenu(self
, char
):
997 self
.tk
.call('tk_traverseWithinMenu', self
._w
, char
)
998 def tk_getMenuButtons(self
):
999 return self
.tk
.call('tk_getMenuButtons', self
._w
)
1000 def tk_nextMenu(self
, count
):
1001 self
.tk
.call('tk_nextMenu', count
)
1002 def tk_nextMenuEntry(self
, count
):
1003 self
.tk
.call('tk_nextMenuEntry', count
)
1004 def tk_invokeMenu(self
):
1005 self
.tk
.call('tk_invokeMenu', self
._w
)
1006 def tk_firstMenu(self
):
1007 self
.tk
.call('tk_firstMenu', self
._w
)
1008 def tk_mbButtonDown(self
):
1009 self
.tk
.call('tk_mbButtonDown', self
._w
)
1010 def activate(self
, index
):
1011 self
.tk
.call(self
._w
, 'activate', index
)
1012 def add(self
, itemType
, cnf
={}):
1013 apply(self
.tk
.call
, (self
._w
, 'add', itemType
)
1014 + self
._options
(cnf
))
1015 def add_cascade(self
, cnf
={}):
1016 self
.add('cascade', cnf
)
1017 def add_checkbutton(self
, cnf
={}):
1018 self
.add('checkbutton', cnf
)
1019 def add_command(self
, cnf
={}):
1020 self
.add('command', cnf
)
1021 def add_radiobutton(self
, cnf
={}):
1022 self
.add('radiobutton', cnf
)
1023 def add_separator(self
, cnf
={}):
1024 self
.add('separator', cnf
)
1025 def delete(self
, index1
, index2
=None):
1026 self
.tk
.call(self
._w
, 'delete', index1
, index2
)
1027 def entryconfig(self
, index
, cnf
={}):
1028 apply(self
.tk
.call
, (self
._w
, 'entryconfigure', index
)
1029 + self
._options
(cnf
))
1030 def index(self
, index
):
1031 i
= self
.tk
.call(self
._w
, 'index', index
)
1032 if i
== 'none': return None
1033 return self
.tk
.getint(i
)
1034 def invoke(self
, index
):
1035 return self
.tk
.call(self
._w
, 'invoke', index
)
1036 def post(self
, x
, y
):
1037 self
.tk
.call(self
._w
, 'post', x
, y
)
1039 self
.tk
.call(self
._w
, 'unpost')
1040 def yposition(self
, index
):
1041 return self
.tk
.getint(self
.tk
.call(
1042 self
._w
, 'yposition', index
))
1044 class Menubutton(Widget
):
1045 def __init__(self
, master
=None, cnf
={}):
1046 Widget
.__init
__(self
, master
, 'menubutton', cnf
)
1048 class Message(Widget
):
1049 def __init__(self
, master
=None, cnf
={}):
1050 Widget
.__init
__(self
, master
, 'message', cnf
)
1052 class Radiobutton(Widget
):
1053 def __init__(self
, master
=None, cnf
={}):
1054 Widget
.__init
__(self
, master
, 'radiobutton', cnf
)
1056 self
.tk
.call(self
._w
, 'deselect')
1058 self
.tk
.call(self
._w
, 'flash')
1060 self
.tk
.call(self
._w
, 'invoke')
1062 self
.tk
.call(self
._w
, 'select')
1064 class Scale(Widget
):
1065 def __init__(self
, master
=None, cnf
={}):
1066 Widget
.__init
__(self
, master
, 'scale', cnf
)
1068 return self
.tk
.getint(self
.tk
.call(self
._w
, 'get'))
1069 def set(self
, value
):
1070 self
.tk
.call(self
._w
, 'set', value
)
1072 class Scrollbar(Widget
):
1073 def __init__(self
, master
=None, cnf
={}):
1074 Widget
.__init
__(self
, master
, 'scrollbar', cnf
)
1076 return self
._getints
(self
.tk
.call(self
._w
, 'get'))
1077 def set(self
, totalUnits
, windowUnits
, firstUnit
, lastUnit
):
1078 self
.tk
.call(self
._w
, 'set',
1079 totalUnits
, windowUnits
, firstUnit
, lastUnit
)
1082 def __init__(self
, master
=None, cnf
={}):
1083 Widget
.__init
__(self
, master
, 'text', cnf
)
1084 def tk_textSelectTo(self
, index
):
1085 self
.tk
.call('tk_textSelectTo', self
._w
, index
)
1086 def tk_textBackspace(self
):
1087 self
.tk
.call('tk_textBackspace', self
._w
)
1088 def tk_textIndexCloser(self
, a
, b
, c
):
1089 self
.tk
.call('tk_textIndexCloser', self
._w
, a
, b
, c
)
1090 def tk_textResetAnchor(self
, index
):
1091 self
.tk
.call('tk_textResetAnchor', self
._w
, index
)
1092 def compare(self
, index1
, op
, index2
):
1093 return self
.tk
.getboolean(self
.tk
.call(
1094 self
._w
, 'compare', index1
, op
, index2
))
1095 def debug(self
, boolean
=None):
1096 return self
.tk
.getboolean(self
.tk
.call(
1097 self
._w
, 'debug', boolean
))
1098 def delete(self
, index1
, index2
=None):
1099 self
.tk
.call(self
._w
, 'delete', index1
, index2
)
1100 def get(self
, index1
, index2
=None):
1101 return self
.tk
.call(self
._w
, 'get', index1
, index2
)
1102 def index(self
, index
):
1103 return self
.tk
.call(self
._w
, 'index', index
)
1104 def insert(self
, index
, chars
):
1105 self
.tk
.call(self
._w
, 'insert', index
, chars
)
1106 def mark_names(self
):
1107 return self
.tk
.splitlist(self
.tk
.call(
1108 self
._w
, 'mark', 'names'))
1109 def mark_set(self
, markName
, index
):
1110 self
.tk
.call(self
._w
, 'mark', 'set', markName
, index
)
1111 def mark_unset(self
, markNames
):
1112 apply(self
.tk
.call
, (self
._w
, 'mark', 'unset') + markNames
)
1113 def scan_mark(self
, y
):
1114 self
.tk
.call(self
._w
, 'scan', 'mark', y
)
1115 def scan_dragto(self
, y
):
1116 self
.tk
.call(self
._w
, 'scan', 'dragto', y
)
1117 def tag_add(self
, tagName
, index1
, index2
=None):
1119 self
._w
, 'tag', 'add', tagName
, index1
, index2
)
1120 def tag_unbind(self
, tagName
, sequence
):
1121 self
.tk
.call(self
._w
, 'tag', 'bind', tagName
, sequence
, '')
1122 def tag_bind(self
, tagName
, sequence
, func
, add
=''):
1124 name
= self
._register
(func
, self
._substitute
)
1125 self
.tk
.call(self
._w
, 'tag', 'bind',
1127 (add
+ name
,) + self
._subst
_format
)
1128 def tag_config(self
, tagName
, cnf
={}):
1130 (self
._w
, 'tag', 'configure', tagName
)
1131 + self
._options
(cnf
))
1132 def tag_delete(self
, *tagNames
):
1133 apply(self
.tk
.call
, (self
._w
, 'tag', 'delete') + tagNames
)
1134 def tag_lower(self
, tagName
, belowThis
=None):
1135 self
.tk
.call(self
._w
, 'tag', 'lower', tagName
, belowThis
)
1136 def tag_names(self
, index
=None):
1137 return self
.tk
.splitlist(
1138 self
.tk
.call(self
._w
, 'tag', 'names', index
))
1139 def tag_nextrange(self
, tagName
, index1
, index2
=None):
1140 return self
.tk
.splitlist(self
.tk
.call(
1141 self
._w
, 'tag', 'nextrange', index1
, index2
))
1142 def tag_raise(self
, tagName
, aboveThis
=None):
1144 self
._w
, 'tag', 'raise', tagName
, aboveThis
)
1145 def tag_ranges(self
, tagName
):
1146 return self
.tk
.splitlist(self
.tk
.call(
1147 self
._w
, 'tag', 'ranges', tagName
))
1148 def tag_remove(self
, tagName
, index1
, index2
=None):
1150 self
._w
, 'tag', 'remove', tagName
, index1
, index2
)
1151 def yview(self
, what
):
1152 self
.tk
.call(self
._w
, 'yview', what
)
1153 def yview_pickplace(self
, what
):
1154 self
.tk
.call(self
._w
, 'yview', '-pickplace', what
)
1156 ######################################################################
1159 class Studbutton(Button
):
1160 def __init__(self
, master
=None, cnf
={}):
1161 Widget
.__init
__(self
, master
, 'studbutton', cnf
)
1162 self
.bind('<Any-Enter>', self
.tk_butEnter
)
1163 self
.bind('<Any-Leave>', self
.tk_butLeave
)
1164 self
.bind('<1>', self
.tk_butDown
)
1165 self
.bind('<ButtonRelease-1>', self
.tk_butUp
)
1167 class Tributton(Button
):
1168 def __init__(self
, master
=None, cnf
={}):
1169 Widget
.__init
__(self
, master
, 'tributton', cnf
)
1170 self
.bind('<Any-Enter>', self
.tk_butEnter
)
1171 self
.bind('<Any-Leave>', self
.tk_butLeave
)
1172 self
.bind('<1>', self
.tk_butDown
)
1173 self
.bind('<ButtonRelease-1>', self
.tk_butUp
)