blob: e9e641c8d1c90cc7e21d9fb3a602f7ca8356e4cf [file] [log] [blame]
Guido van Rossum18468821994-06-20 07:49:28 +00001# Tkinter.py -- Tk/Tcl widget wrappers
2import tkinter
3from tkinter import TclError
4
5class _Dummy:
6 def meth(self): return
7
8def _isfunctype(func):
9 return type(func) in (type(_Dummy.meth), type(_isfunctype))
10
11FunctionType = type(_isfunctype)
12ClassType = type(_Dummy)
13MethodType = type(_Dummy.meth)
14
15def tkerror(err):
16 pass
17
18class Event:
19 pass
20
21class Misc:
22 def tk_strictMotif(self, boolean=None):
23 self.tk.getboolean(self.tk.call(
24 'set', 'tk_strictMotif', boolean))
25 def waitvar(self, name='VAR'):
26 self.tk.call('tkwait', 'variable', name)
27 def setvar(self, name='VAR', value='1'):
28 self.tk.setvar(name, value)
29 def focus(self):
30 self.tk.call('focus', self._w)
31 def focus_default(self):
32 self.tk.call('focus', 'default', self._w)
33 def focus_none(self):
34 self.tk.call('focus', 'none')
35 #XXX focus_get?
36 def after(self, ms, func=None, *args):
37 if not func:
38 self.tk.call('after', ms)
39 else:
40 name = self._register(func)
41 apply(self.tk.call, ('after', ms, name) + args)
42 #XXX grab_current
43 def grab_release(self):
44 self.tk.call('grab', 'release', self._w)
45 def grab_set(self):
46 self.tk.call('grab', 'set', self._w)
47 def grab_set_global(self):
48 self.tk.call('grab', 'set', '-global', self._w)
49 def grab_status(self):
50 self.tk.call('grab', 'status', self._w)
51 def lower(self, belowThis=None):
52 self.tk.call('lower', self._w, belowThis)
53 def selection_clear(self):
54 self.tk.call('selection', 'clear', self._w)
55 def selection_get(self, type=None):
56 self.tk.call('selection', 'get', type)
57 def selection_handle(self, func, type=None, format=None):
58 name = self._register(func)
59 self.tk.call('selection', 'handle',
60 self._w, name, type, format)
61 #XXX def selection_own(self):
62 # self.tk.call('selection', 'own', self._w)
63 def send(self, interp, cmd, *args): #XXX
64 return apply(self.tk.call, ('send', interp, cmd) + args)
65 def colormodel(self, value=None):
66 return self.tk.call('tk', 'colormodel', self._w, value)
67 def winfo_atom(self, name):
68 return self.tk.getint(self.tk.call('winfo', 'atom', name))
69 def winfo_atomname(self, id):
70 return self.tk.call('winfo', 'atomname', id)
71 def winfo_cells(self):
72 return self.tk.getint(
73 self.tk.call('winfo', 'cells', self._w))
74 #XXX winfo_children
75 def winfo_class(self):
76 return self.tk.call('winfo', 'class', self._w)
77 def winfo_containing(self, rootX, rootY):
78 return self.tk.call('winfo', 'containing', rootx, rootY)
79 def winfo_depth(self):
80 return self.tk.getint(self.tk.call('winfo', 'depth', self._w))
81 def winfo_exists(self):
82 return self.tk.getint(
83 self.tk.call('winfo', 'exists', self._w))
84 def winfo_fpixels(self, number):
85 return self.tk.getdouble(self.tk.call(
86 'winfo', 'fpixels', self._w, number))
87 def winfo_geometry(self):
88 return self.tk.call('winfo', 'geometry', self._w)
89 def winfo_height(self):
90 return self.tk.getint(
91 self.tk.call('winfo', 'height', self._w))
92 def winfo_id(self):
93 return self.tk.getint(
94 self.tk.call('winfo', 'id', self._w))
95 def winfo_interps(self):
96 return self.tk.splitlist(
97 self.tk.call('winfo', 'interps'))
98 def winfo_ismapped(self):
99 return self.tk.getint(
100 self.tk.call('winfo', 'ismapped', self._w))
101 def winfo_name(self):
102 return self.tk.call('winfo', 'name', self._w)
103 def winfo_parent(self):
104 return self.tk.call('winfo', 'parent', self._w)
105 def winfo_pathname(self, id):
106 return self.tk.call('winfo', 'pathname', id)
107 def winfo_pixels(self, number):
108 return self.tk.getint(
109 self.tk.call('winfo', 'pixels', self._w, number))
110 def winfo_reqheight(self):
111 return self.tk.getint(
112 self.tk.call('winfo', 'reqheight', self._w))
113 def winfo_reqwidth(self):
114 return self.tk.getint(
115 self.tk.call('winfo', 'reqwidth', self._w))
116 def winfo_rgb(self, color):
117 return self._getints(
118 self.tk.call('winfo', 'rgb', self._w, color))
119 def winfo_rootx(self):
120 return self.tk.getint(
121 self.tk.call('winfo', 'rootx', self._w))
122 def winfo_rooty(self):
123 return self.tk.getint(
124 self.tk.call('winfo', 'rooty', self._w))
125 def winfo_screen(self):
126 return self.tk.call('winfo', 'screen', self._w)
127 def winfo_screencells(self):
128 return self.tk.getint(
129 self.tk.call('winfo', 'screencells', self._w))
130 def winfo_screendepth(self):
131 return self.tk.getint(
132 self.tk.call('winfo', 'screendepth', self._w))
133 def winfo_screenheight(self):
134 return self.tk.getint(
135 self.tk.call('winfo', 'screenheight', self._w))
136 def winfo_screenmmheight(self):
137 return self.tk.getint(
138 self.tk.call('winfo', 'screenmmheight', self._w))
139 def winfo_screenmmwidth(self):
140 return self.tk.getint(
141 self.tk.call('winfo', 'screenmmwidth', self._w))
142 def winfo_screenvisual(self):
143 return self.tk.call('winfo', 'screenvisual', self._w)
144 def winfo_screenwidth(self):
145 return self.tk.getint(
146 self.tk.call('winfo', 'screenwidth', self._w))
147 def winfo_toplevel(self):
148 return self.tk.call('winfo', 'toplevel', self._w)
149 def winfo_visual(self):
150 return self.tk.call('winfo', 'visual', self._w)
151 def winfo_vrootheight(self):
152 return self.tk.getint(
153 self.tk.call('winfo', 'vrootheight', self._w))
154 def winfo_vrootwidth(self):
155 return self.tk.getint(
156 self.tk.call('winfo', 'vrootwidth', self._w))
157 def winfo_vrootx(self):
158 return self.tk.getint(
159 self.tk.call('winfo', 'vrootx', self._w))
160 def winfo_vrooty(self):
161 return self.tk.getint(
162 self.tk.call('winfo', 'vrooty', self._w))
163 def winfo_width(self):
164 return self.tk.getint(
165 self.tk.call('winfo', 'width', self._w))
166 def winfo_x(self):
167 return self.tk.getint(
168 self.tk.call('winfo', 'x', self._w))
169 def winfo_y(self):
170 return self.tk.getint(
171 self.tk.call('winfo', 'y', self._w))
172 def update(self):
173 self.tk.call('update')
174 def update_idletasks(self):
175 self.tk.call('update', 'idletasks')
176 def bind(self, sequence, func, add=''):
177 global _substitute, _subst_prefix
178 if add: add = '+'
179 name = self._register(func, _substitute)
180 self.tk.call('bind', self._w, sequence,
181 (add + name,) + _subst_prefix)
182 def bind_all(self, sequence, func, add=''):
183 global _substitute, _subst_prefix
184 if add: add = '+'
185 name = self._register(func, _substitute)
186 self.tk.call('bind', 'all' , sequence,
187 (add + `name`,) + _subst_prefix)
188 def bind_class(self, className, sequence, func, add=''):
189 global _substitute, _subst_prefix
190 if add: add = '+'
191 name = self._register(func, _substitute)
192 self.tk.call('bind', className , sequence,
193 (add + name,) + _subst_prefix)
194 def mainloop(self):
195 self.tk.mainloop()
196 def quit(self):
197 self.tk.quit()
198 # Utilities
199 def _getints(self, string):
200 if string:
201 res = ()
202 for v in self.tk.split(string):
203 res = res + (self.tk.getint(v),)
204 return res
205 else:
206 return string
207 def _getboolean(self, string):
208 if string:
209 return self.tk.getboolean(string)
210 else:
211 return string
212 def _options(self, cnf):
213 res = ()
214 for k, v in cnf.items():
215 if _isfunctype(v):
216 v = self._register(v)
217 res = res + ('-'+k, v)
218 return res
219 def _register(self, func, subst=None):
220 f = func
221 f = _CallSafely(func, subst).__call__
222 name = `id(f)`
223 if hasattr(func, 'im_func'):
224 func = func.im_func
225 if hasattr(func, 'func_name') and \
226 type(func.func_name) == type(''):
227 name = name + func.func_name
228 self.tk.createcommand(name, f)
229 return name
230
231_subst_prefix = ('%#', '%b', '%f', '%h', '%k',
232 '%s', '%t', '%w', '%x', '%y',
233 '%A', '%E', '%K', '%N', '%T', '%X', '%Y')
234
235def _substitute(*args):
236 global default_root
237 global _subst_prefix
238 tk = default_root.tk
239 if len(args) != len(_subst_prefix): return args
240 nsign, b, f, h, k, s, t, w, x, y, A, E, K, N, T, X, Y = args
241 # Missing: (a, c, d, m, o, v, B, R, W)
242 #XXX Convert %W (_w) to class instance?
243 e = Event()
244 e.serial = tk.getint(nsign)
245 e.num = tk.getint(b)
246 try: e.focus = tk.getboolean(f)
247 except TclError: pass
248 e.height = tk.getint(h)
249 e.keycode = tk.getint(k)
250 e.state = tk.getint(s)
251 e.time = tk.getint(t)
252 e.width = tk.getint(w)
253 e.x = tk.getint(x)
254 e.y = tk.getint(y)
255 e.char = A
256 try: e.send_event = tk.getboolean(E)
257 except TclError: pass
258 e.keysym = K
259 e.keysym_num = tk.getint(N)
260 e.type = T
261 #XXX %W stuff
262 e.x_root = tk.getint(X)
263 e.y_root = tk.getint(Y)
264 return (e,)
265
266class _CallSafely:
267 def __init__(self, func, subst=None):
268 self.func = func
269 self.subst = subst
270 def __call__(self, *args):
271 if self.subst:
272 args = self.apply_func(self.subst, args)
273 args = self.apply_func(self.func, args)
274 def apply_func(self, func, args):
275 import sys
276 try:
277 return apply(func, args)
278 except:
279 try:
280 try:
281 t = sys.exc_traceback
282 while t:
283 sys.stderr.write(
284 ' %s, line %s\n' %
285 (t.tb_frame.f_code,
286 t.tb_lineno))
287 t = t.tb_next
288 finally:
289 sys.stderr.write('%s: %s\n' %
290 (sys.exc_type,
291 sys.exc_value))
292 except:
293 print '*** Error in error handling ***'
294 print sys.exc_type, ':', sys.exc_value
295
296class Wm:
297 def aspect(self,
298 minNumer=None, minDenom=None,
299 maxNumer=None, maxDenom=None):
300 return self._getints(
301 self.tk.call('wm', 'aspect', self._w,
302 minNumer, minDenom,
303 maxNumer, maxDenom))
304 def client(self, name=None):
305 return self.tk.call('wm', 'client', self._w, name)
306 def command(self, value=None):
307 return self.tk.call('wm', 'command', self._w, value)
308 def deiconify(self):
309 return self.tk.call('wm', 'deiconify', self._w)
310 def focusmodel(self, model=None):
311 return self.tk.call('wm', 'focusmodel', self._w, model)
312 def frame(self):
313 return self.tk.call('wm', 'frame', self._w)
314 def geometry(self, newGeometry=None):
315 return self.tk.call('wm', 'geometry', self._w, newGeometry)
316 def grid(self,
317 baseWidht=None, baseHeight=None,
318 widthInc=None, heightInc=None):
319 return self._getints(self.tk.call(
320 'wm', 'grid', self._w,
321 baseWidht, baseHeight, widthInc, heightInc))
322 def group(self, pathName=None):
323 return self.tk.call('wm', 'group', self._w, pathName)
324 def iconbitmap(self, bitmap=None):
325 return self.tk.call('wm', 'iconbitmap', self._w, bitmap)
326 def iconify(self):
327 return self.tk.call('wm', 'iconify', self._w)
328 def iconmask(self, bitmap=None):
329 return self.tk.call('wm', 'iconmask', self._w, bitmap)
330 def iconname(self, newName=None):
331 return self.tk.call('wm', 'iconname', self._w, newName)
332 def iconposition(self, x=None, y=None):
333 return self._getints(self.tk.call(
334 'wm', 'iconposition', self._w, x, y))
335 def iconwindow(self, pathName=None):
336 return self.tk.call('wm', 'iconwindow', self._w, pathName)
337 def maxsize(self, width=None, height=None):
338 return self._getints(self.tk.call(
339 'wm', 'maxsize', self._w, width, height))
340 def minsize(self, width=None, height=None):
341 return self._getints(self.tk.call(
342 'wm', 'minsize', self._w, width, height))
343 def overrideredirect(self, boolean=None):
344 return self._getboolean(self.tk.call(
345 'wm', 'overrideredirect', self._w, boolean))
346 def positionfrom(self, who=None):
347 return self.tk.call('wm', 'positionfrom', self._w, who)
348 def protocol(self, name=None, func=None):
349 if _isfunctype(func):
350 command = self._register(func)
351 else:
352 command = func
353 return self.tk.call(
354 'wm', 'protocol', self._w, name, command)
355 def sizefrom(self, who=None):
356 return self.tk.call('wm', 'sizefrom', self._w, who)
357 def state(self):
358 return self.tk.call('wm', 'state', self._w)
359 def title(self, string=None):
360 return self.tk.call('wm', 'title', self._w, string)
361 def transient(self, master=None):
362 return self.tk.call('wm', 'transient', self._w, master)
363 def withdraw(self):
364 return self.tk.call('wm', 'withdraw', self._w)
365
366class Tk(Misc, Wm):
367 _w = '.'
368 def __init__(self, screenName=None, baseName=None, className='Tk'):
369 if baseName is None:
370 import sys, os
371 baseName = os.path.basename(sys.argv[0])
372 if baseName[-3:] == '.py': baseName = baseName[:-3]
373 self.tk = tkinter.create(screenName, baseName, className)
374 self.tk.createcommand('tkerror', tkerror)
375 def __del__(self):
376 self.tk.call('destroy', '.')
377 def __str__(self):
378 return '.'
379
380class Pack:
381 def config(self, cnf={}):
382 apply(self.tk.call,
383 ('pack', 'configure', self._w)
384 + self._options(cnf))
385 pack = config
386 def __setitem__(self, key, value):
387 Pack.config({key: value})
388 def forget(self):
389 self.tk.call('pack', 'forget', self._w)
390 def newinfo(self):
391 return self.tk.call('pack', 'newinfo', self._w)
392 info = newinfo
393 def propagate(self, boolean=None):
394 if boolean:
395 self.tk.call('pack', 'propagate', self._w)
396 else:
397 return self._getboolean(self.tk.call(
398 'pack', 'propagate', self._w))
399 def slaves(self):
400 return self.tk.splitlist(self.tk.call(
401 'pack', 'slaves', self._w))
402
403class Place:
404 def config(self, cnf={}):
405 apply(self.tk.call,
406 ('place', 'configure', self._w)
407 + self._options(cnf))
408 place = config
409 def __setitem__(self, key, value):
410 Place.config({key: value})
411 def forget(self):
412 self.tk.call('place', 'forget', self._w)
413 def info(self):
414 return self.tk.call('place', 'info', self._w)
415 def slaves(self):
416 return self.tk.splitlist(self.tk.call(
417 'place', 'slaves', self._w))
418
419default_root = None
420
421class Widget(Misc, Pack, Place):
422 def __init__(self, master, widgetName, cnf={}, extra=()):
423 global default_root
424 if not master:
425 if not default_root:
426 default_root = Tk()
427 master = default_root
428 if not default_root:
429 default_root = master
430 self.master = master
431 self.tk = master.tk
432 if cnf.has_key('name'):
433 name = cnf['name']
434 del cnf['name']
435 else:
436 name = `id(self)`
437 if master._w=='.':
438 self._w = '.' + name
439 else:
440 self._w = master._w + '.' + name
441 self.widgetName = widgetName
442 apply(self.tk.call, (widgetName, self._w) + extra)
443 Widget.config(self, cnf)
444 def config(self, cnf={}):
445 for k in cnf.keys():
446 if type(k) == ClassType:
447 k.config(self, cnf[k])
448 del cnf[k]
449 apply(self.tk.call, (self._w, 'configure')
450 + self._options(cnf))
451 def __getitem__(self, key):
452 v = self.tk.split(self.tk.call(
453 self._w, 'configure', '-' + key))
454 return v[4]
455 def __setitem__(self, key, value):
456 Widget.config(self, {key: value})
457 def __str__(self):
458 return self._w
459 def __del__(self):
460 self.tk.call('destroy', self._w)
461 destroy = __del__
462 def _do(self, name, args=()):
463 apply(self.tk.call, (self._w, name) + args)
464
465class Toplevel(Widget, Wm):
466 def __init__(self, master=None, cnf={}):
467 extra = ()
468 if cnf.has_key('screen'):
469 extra = ('-screen', cnf['screen'])
470 del cnf['screen']
471 if cnf.has_key('class'):
472 extra = extra + ('-class', cnf['class'])
473 del cnf['class']
474 Widget.__init__(self, master, 'toplevel', cnf, extra)
475 self.iconname(self.tk.call('wm', 'iconname', '.'))
476 self.title(self.tk.call('wm', 'title', '.'))
477
478class Button(Widget):
479 def __init__(self, master=None, cnf={}):
480 Widget.__init__(self, master, 'button', cnf)
481 def tk_butEnter(self):
482 self.tk.call('tk_butEnter', self._w)
483 def tk_butLeave(self):
484 self.tk.call('tk_butLeave', self._w)
485 def tk_butDown(self):
486 self.tk.call('tk_butDown', self._w)
487 def tk_butUp(self):
488 self.tk.call('tk_butUp', self._w)
489 def flash(self):
490 self.tk.call(self._w, 'flash')
491 def invoke(self):
492 self.tk.call(self._w, 'invoke')
493
494# Indices:
495def AtEnd():
496 return 'end'
497def AtInsert():
498 return 'insert'
499def AtSelFirst():
500 return 'sel.first'
501def AtSelLast():
502 return 'sel.last'
503def At(x, y=None):
504 if y:
505 return '@' + `x` + ',' + `y`
506 else:
507 return '@' + `x`
508
509class Canvas(Widget):
510 def __init__(self, master=None, cnf={}):
511 Widget.__init__(self, master, 'canvas', cnf)
512 def addtag(self, *args):
513 self._do('addtag', args)
514 def bbox(self, *args):
515 return self._getints(self._do('bbox', args))
516 def bind(self, tagOrId, sequence, func, add=''):
517 global _substitute, _subst_prefix
518 if add: add='+'
519 name = self._register(func, _substitute)
520 self.tk.call(self._w, 'bind', tagOrId, sequence,
521 (add + name,) + _subst_prefix)
522 def canvasx(self, screenx, gridspacing=None):
523 return self.tk.getint(self.tk.call(
524 self._w, 'canvasx', screenx, gridspacing))
525 def canvasy(self, screeny, gridspacing=None):
526 return self.tk.getint(self.tk.call(
527 self._w, 'canvasy', screeny, gridspacing))
528 def coords(self, *args):
529 return self._do('coords', args)
530 def _create(self, itemType, args): # Args: (value, value, ..., cnf={})
531 cnf = args[-1]
532 if type(cnf) == type({}):
533 args = args[:-1]
534 else:
535 cnf = {}
536 v = (self._w, 'create', itemType) + args
537 for k in cnf.keys():
538 v = v + ('-' + k, cnf[k])
539 return self.tk.getint(apply(self.tk.call, v))
540 def create_arc(self, *args):
541 Canvas._create(self, 'arc', args)
542 def create_bitmap(self, *args):
543 Canvas._create(self, 'bitmap', args)
544 def create_line(self, *args):
545 Canvas._create(self, 'line', args)
546 def create_oval(self, *args):
547 Canvas._create(self, 'oval', args)
548 def create_polygon(self, *args):
549 Canvas._create(self, 'polygon', args)
550 def create_rectangle(self, *args):
551 Canvas._create(self, 'rectangle', args)
552 def create_text(self, *args):
553 Canvas._create(self, 'text', args)
554 def create_window(self, *args):
555 Canvas._create(self, 'window', args)
556 def dchars(self, *args):
557 self._do('dchars', args)
558 def delete(self, *args):
559 self._do('delete', args)
560 def dtag(self, *args):
561 self._do('dtag', args)
562 def find(self, *args):
563 self.tk.splitlist(self._do('find', args))
564 def focus(self, *args):
565 return self._do('focus', args)
566 def gettags(self, *args):
567 return self.tk.splitlist(self._do('gettags', args))
568 def icursor(self, *args):
569 self._do('icursor', args)
570 def index(self, *args):
571 return self.tk.getint(self._do('index', args))
572 def insert(self, *args):
573 self._do('insert', args)
574 def itemconfig(self, tagOrId, cnf={}):
575 self._do('itemconfigure', (tagOrId,) + self._options(cnf))
576 def lower(self, *args):
577 self._do('lower', args)
578 def move(self, *args):
579 self._do('move', args)
580 def postscript(self, cnf={}):
581 return self._do('postscript', self._options(cnf))
582 def tkraise(self, *args):
583 self._do('raise', args)
584 def scale(self, *args):
585 self._do('scale', args)
586 def scan_mark(self, x, y):
587 self.tk.call(self._w, 'scan', 'mark', x, y)
588 def scan_dragto(self, x, y):
589 self.tk.call(self._w, 'scan', 'dragto', x, y)
590 def select_adjust(self, tagOrId, index):
591 self.tk.call(
592 self._w, 'select', 'adjust', tagOrId, index)
593 def select_clear(self):
594 self.tk.call(self._w, 'select', 'clear')
595 def select_from(self, tagOrId, index):
596 self.tk.call(
597 self._w, 'select', 'from', tagOrId, index)
598 def select_item(self):
599 self.tk.call(self._w, 'select', 'item')
600 def select_to(self, tagOrId, index):
601 self.tk.call(
602 self._w, 'select', 'to', tagOrId, index)
603 def type(self, tagOrId):
604 return self.tk.splitlist(self.tk.call(
605 self._w, 'type', tagOrId))
606 def xview(self, index):
607 self.tk.call(self._w, 'xview', index)
608 def yview(self, index):
609 self.tk.call(self._w, 'yview', index)
610
611class Checkbutton(Widget):
612 def __init__(self, master=None, cnf={}):
613 Widget.__init__(self, master, 'checkbutton', cnf)
614 def deselect(self):
615 self.tk.call(self._w, 'deselect')
616 def flash(self):
617 self.tk.call(self._w, 'flash')
618 def invoke(self):
619 self.tk.call(self._w, 'invoke')
620 def select(self):
621 self.tk.call(self._w, 'select')
622 def toggle(self):
623 self.tk.call(self._w, 'toggle')
624
625class Entry(Widget):
626 def __init__(self, master=None, cnf={}):
627 Widget.__init__(self, master, 'entry', cnf)
628 def tk_entryBackspace(self):
629 self.tk.call('tk_entryBackspace', self._w)
630 def tk_entryBackword(self):
631 self.tk.call('tk_entryBackword', self._w)
632 def tk_entrySeeCaret(self):
633 self.tk.call('tk_entrySeeCaret', self._w)
634 def delete(self, first, last=None):
635 self.tk.call(self._w, 'delete', first, last)
636 def get(self):
637 return self.tk.call(self._w, 'get')
638 def icursor(self, index):
639 self.tk.call(self._w, 'icursor', index)
640 def index(self, index):
641 return self.tk.getint(self.tk.call(
642 self._w, 'index', index))
643 def insert(self, index, string):
644 self.tk.call(self._w, 'insert', index, string)
645 def scan_mark(self, x):
646 self.tk.call(self._w, 'scan', 'mark', x)
647 def scan_dragto(self, x):
648 self.tk.call(self._w, 'scan', 'dragto', x)
649 def select_adjust(self, index):
650 self.tk.call(self._w, 'select', 'adjust', index)
651 def select_clear(self):
652 self.tk.call(self._w, 'select', 'clear')
653 def select_from(self, index):
654 self.tk.call(self._w, 'select', 'from', index)
655 def select_to(self, index):
656 self.tk.call(self._w, 'select', 'to', index)
657 def select_view(self, index):
658 self.tk.call(self._w, 'select', 'view', index)
659
660class Frame(Widget):
661 def __init__(self, master=None, cnf={}):
662 extra = ()
663 if cnf.has_key('class'):
664 extra = ('-class', cnf['class'])
665 del cnf['class']
666 Widget.__init__(self, master, 'frame', cnf, extra)
667 def tk_menuBar(self, *args):
668 apply(self.tk.call, ('tk_menuBar', self._w) + args)
669
670class Label(Widget):
671 def __init__(self, master=None, cnf={}):
672 Widget.__init__(self, master, 'label', cnf)
673
674class Listbox(Widget):
675 def __init__(self, master=None, cnf={}):
676 Widget.__init__(self, master, 'listbox', cnf)
677 def tk_listboxSingleSelect(self):
678 self.tk.call('tk_listboxSingleSelect', self._w)
679 def curselection(self):
680 return self.tk.splitlist(self.tk.call(
681 self._w, 'curselection'))
682 def delete(self, first, last=None):
683 self.tk.call(self._w, 'delete', first, last)
684 def get(self, index):
685 return self.tk.call(self._w, 'get', index)
686 def insert(self, index, *elements):
687 apply(self.tk.call,
688 (self._w, 'insert', index) + elements)
689 def nearest(self, y):
690 return self.tk.getint(self.tk.call(
691 self._w, 'nearest', y))
692 def scan_mark(self, x, y):
693 self.tk.call(self._w, 'scan', 'mark', x, y)
694 def scan_dragto(self, x, y):
695 self.tk.call(self._w, 'scan', 'dragto', x, y)
696 def select_adjust(self, index):
697 self.tk.call(self._w, 'select', 'adjust', index)
698 def select_clear(self):
699 self.tk.call(self._w, 'select', 'clear')
700 def select_from(self, index):
701 self.tk.call(self._w, 'select', 'from', index)
702 def select_to(self, index):
703 self.tk.call(self._w, 'select', 'to', index)
704 def size(self):
705 return self.tk.getint(self.tk.call(self._w, 'size'))
706 def xview(self, index):
707 self.tk.call(self._w, 'xview', index)
708 def yview(self, index):
709 self.tk.call(self._w, 'yview', index)
710
711class Menu(Widget):
712 def __init__(self, master=None, cnf={}):
713 Widget.__init__(self, master, 'menu', cnf)
714 def tk_menuBar(self, *args):
715 apply(self.tk.call, ('tk_menuBar', self._w) + args)
716 def tk_bindForTraversal(self):
717 self.tk.call('tk_bindForTraversal', self._w)
718 def tk_mbPost(self):
719 self.tk.call('tk_mbPost', self._w)
720 def tk_mbUnpost(self):
721 self.tk.call('tk_mbUnpost')
722 def tk_traverseToMenu(self, char):
723 self.tk.call('tk_traverseToMenu', self._w, char)
724 def tk_traverseWithinMenu(self, char):
725 self.tk.call('tk_traverseWithinMenu', self._w, char)
726 def tk_getMenuButtons(self):
727 return self.tk.call('tk_getMenuButtons', self._w)
728 def tk_nextMenu(self, count):
729 self.tk.call('tk_nextMenu', count)
730 def tk_nextMenuEntry(self, count):
731 self.tk.call('tk_nextMenuEntry', count)
732 def tk_invokeMenu(self):
733 self.tk.call('tk_invokeMenu', self._w)
734 def tk_firstMenu(self):
735 self.tk.call('tk_firstMenu', self._w)
736 def tk_mbButtonDown(self):
737 self.tk.call('tk_mbButtonDown', self._w)
738 def activate(self, index):
739 self.tk.call(self._w, 'activate', index)
740 def add(self, itemType, cnf={}):
741 apply(self.tk.call, (self._w, 'add', itemType)
742 + self._options(cnf))
743 def delete(self, index1, index2=None):
744 self.tk.call(self._w, 'delete', index1, index2)
745 def entryconfig(self, index, cnf={}):
746 apply(self.tk.call, (self._w, 'entryconfigure', index)
747 + self._options(cnf))
748 def index(self, index):
749 return self.tk.call(self._w, 'index', index)
750 def invoke(self, index):
751 return self.tk.call(self._w, 'invoke', index)
752 def post(self, x, y):
753 self.tk.call(self._w, 'post', x, y)
754 def unpost(self):
755 self.tk.call(self._w, 'unpost')
756 def yposition(self, index):
757 return self.tk.getint(self.tk.call(
758 self._w, 'yposition', index))
759
760class Menubutton(Widget):
761 def __init__(self, master=None, cnf={}):
762 Widget.__init__(self, master, 'menubutton', cnf)
763
764class Message(Widget):
765 def __init__(self, master=None, cnf={}):
766 Widget.__init__(self, master, 'message', cnf)
767
768class Radiobutton(Widget):
769 def __init__(self, master=None, cnf={}):
770 Widget.__init__(self, master, 'radiobutton', cnf)
771 def deselect(self):
772 self.tk.call(self._w, 'deselect')
773 def flash(self):
774 self.tk.call(self._w, 'flash')
775 def invoke(self):
776 self.tk.call(self._w, 'invoke')
777 def select(self):
778 self.tk.call(self._w, 'select')
779
780class Scale(Widget):
781 def __init__(self, master=None, cnf={}):
782 Widget.__init__(self, master, 'scale', cnf)
783 def get(self):
784 return self.tk.getint(self.tk.call(self._w, 'get'))
785 def set(self, value):
786 self.tk.call(self._w, 'set', value)
787
788class Scrollbar(Widget):
789 def __init__(self, master=None, cnf={}):
790 Widget.__init__(self, master, 'scrollbar', cnf)
791 def get(self):
792 return self.tk.getints(self.tk.call(self._w, 'get'))
793 def set(self, totalUnits, windowUnits, firstUnit, lastUnit):
794 self.tk.call(self._w, 'set',
795 totalUnits, windowUnits, firstUnit, lastUnit)
796
797class Text(Widget):
798 def __init__(self, master=None, cnf={}):
799 Widget.__init__(self, master, 'text', cnf)
800 def tk_textSelectTo(self, index):
801 self.tk.call('tk_textSelectTo', self._w, index)
802 def tk_textBackspace(self):
803 self.tk.call('tk_textBackspace', self._w)
804 def tk_textIndexCloser(self, a, b, c):
805 self.tk.call('tk_textIndexCloser', self._w, a, b, c)
806 def tk_textResetAnchor(self, index):
807 self.tk.call('tk_textResetAnchor', self._w, index)
808 def compare(self, index1, op, index2):
809 return self.tk.getboolean(self.tk.call(
810 self._w, 'compare', index1, op, index2))
811 def debug(self, boolean=None):
812 return self.tk.getboolean(self.tk.call(
813 self._w, 'debug', boolean))
814 def delete(self, index1, index2=None):
815 self.tk.call(self._w, 'delete', index1, index2)
816 def get(self, index1, index2=None):
817 return self.tk.call(self._w, 'get', index1, index2)
818 def index(self, index):
819 return self.tk.call(self._w, 'index', index)
820 def insert(self, index, chars):
821 self.tk.call(self._w, 'insert', index, chars)
822 def mark_names(self):
823 return self.tk.splitlist(self.tk.call(
824 self._w, 'mark', 'names'))
825 def mark_set(self, markName, index):
826 self.tk.call(self._w, 'mark', 'set', markName, index)
827 def mark_unset(self, markNames):
828 apply(self.tk.call, (self._w, 'mark', 'unset') + markNames)
829 def scan_mark(self, y):
830 self.tk.call(self._w, 'scan', 'mark', y)
831 def scan_dragto(self, y):
832 self.tk.call(self._w, 'scan', 'dragto', y)
833 def tag_add(self, tagName, index1, index2=None):
834 self.tk.call(
835 self._w, 'tag', 'add', tagName, index1, index2)
836 def tag_bind(self, tagName, sequence, func, add=''):
837 global _substitute, _subst_prefix
838 if add: add='+'
839 name = self._register(func, _substitute)
840 self.tk.call(self._w, 'tag', 'bind',
841 tagName, sequence,
842 (add + name,) + _subst_prefix)
843 def tag_config(self, tagName, cnf={}):
844 apply(self.tk.call,
845 (self._w, 'tag', 'configure', tagName)
846 + self._options(cnf))
847 def tag_delete(self, tagNames):
848 apply(self.tk.call, (self._w, 'tag', 'delete')
849 + tagNames)
850 def tag_lower(self, tagName, belowThis=None):
851 self.tk.call(self._w, 'tag', 'lower',
852 tagName, belowThis)
853 def tag_names(self, index=None):
854 return self.tk.splitlist(
855 self.tk.call(self._w, 'tag', 'names', index))
856 def tag_nextrange(self, tagName, index1, index2=None):
857 return self.tk.splitlist(self.tk.call(
858 self._w, 'tag', 'nextrange', index1, index2))
859 def tag_raise(self, tagName, aboveThis=None):
860 self.tk.call(
861 self._w, 'tag', 'raise', tagName, aboveThis)
862 def tag_ranges(self, tagName):
863 return self.tk.splitlist(self.tk.call(
864 self._w, 'tag', 'ranges', tagName))
865 def tag_remove(self, tagName, index1, index2=None):
866 self.tk.call(
867 self._w, 'tag', 'remove', index1, index2)
868 def yview(self, what):
869 self.tk.call(self._w, 'yview', what)
870 def yview_pickplace(self, what):
871 self.tk.call(self._w, 'yview', '-pickplace', what)
872
873#class Dialog:
874