blob: aace39a0636ad233d3de6a0a8c0f03b08247e452 [file] [log] [blame]
Guido van Rossum18468821994-06-20 07:49:28 +00001# Tkinter.py -- Tk/Tcl widget wrappers
Guido van Rossum2dcf5291994-07-06 09:23:20 +00002
Guido van Rossum18468821994-06-20 07:49:28 +00003import tkinter
4from tkinter import TclError
Guido van Rossum7e9394a1995-03-17 16:21:33 +00005from types import *
Guido van Rossuma5773dd1995-09-07 19:22:00 +00006from Tkconstants import *
Guido van Rossum18468821994-06-20 07:49:28 +00007
Guido van Rossum761c5ab1995-07-14 15:29:10 +00008CallableTypes = (FunctionType, MethodType,
9 BuiltinFunctionType, BuiltinMethodType)
10
11TkVersion = eval(tkinter.TK_VERSION)
12TclVersion = eval(tkinter.TCL_VERSION)
Guido van Rossum18468821994-06-20 07:49:28 +000013
Guido van Rossuma22a70a1995-08-04 03:51:48 +000014
Guido van Rossum2dcf5291994-07-06 09:23:20 +000015def _flatten(tuple):
16 res = ()
17 for item in tuple:
18 if type(item) in (TupleType, ListType):
19 res = res + _flatten(item)
Guido van Rossum35f67fb1995-08-04 03:50:29 +000020 elif item is not None:
Guido van Rossum2dcf5291994-07-06 09:23:20 +000021 res = res + (item,)
22 return res
23
24def _cnfmerge(cnfs):
Guido van Rossum761c5ab1995-07-14 15:29:10 +000025 if type(cnfs) is DictionaryType:
26 _fixgeometry(cnfs)
27 return cnfs
28 elif type(cnfs) in (NoneType, StringType):
29
Guido van Rossum2dcf5291994-07-06 09:23:20 +000030 return cnfs
31 else:
32 cnf = {}
33 for c in _flatten(cnfs):
Guido van Rossum761c5ab1995-07-14 15:29:10 +000034 _fixgeometry(c)
Guido van Rossum2dcf5291994-07-06 09:23:20 +000035 for k, v in c.items():
36 cnf[k] = v
37 return cnf
38
Guido van Rossum761c5ab1995-07-14 15:29:10 +000039if TkVersion >= 4.0:
40 _fixg_warning = "Warning: patched up pre-Tk-4.0 geometry option\n"
41 def _fixgeometry(c):
Guido van Rossum35f67fb1995-08-04 03:50:29 +000042 if c and c.has_key('geometry'):
Guido van Rossum761c5ab1995-07-14 15:29:10 +000043 wh = _parsegeometry(c['geometry'])
44 if wh:
45 # Print warning message -- once
46 global _fixg_warning
47 if _fixg_warning:
48 import sys
49 sys.stderr.write(_fixg_warning)
50 _fixg_warning = None
51 w, h = wh
52 c['width'] = w
53 c['height'] = h
54 del c['geometry']
55 def _parsegeometry(s):
56 from string import splitfields
57 fields = splitfields(s, 'x')
58 if len(fields) == 2:
59 return tuple(fields)
60 # else: return None
61else:
62 def _fixgeometry(c): pass
63
Guido van Rossum2dcf5291994-07-06 09:23:20 +000064class Event:
65 pass
66
Guido van Rossumaec5dc91994-06-27 07:55:12 +000067_default_root = None
68
Guido van Rossum45853db1994-06-20 12:19:19 +000069def _tkerror(err):
Guido van Rossum18468821994-06-20 07:49:28 +000070 pass
71
Guido van Rossum97aeca11994-07-07 13:12:12 +000072def _exit(code='0'):
73 import sys
74 sys.exit(getint(code))
75
Guido van Rossumaec5dc91994-06-27 07:55:12 +000076_varnum = 0
77class Variable:
78 def __init__(self, master=None):
79 global _default_root
80 global _varnum
81 if master:
82 self._tk = master.tk
83 else:
84 self._tk = _default_root.tk
85 self._name = 'PY_VAR' + `_varnum`
86 _varnum = _varnum + 1
87 def __del__(self):
88 self._tk.unsetvar(self._name)
89 def __str__(self):
90 return self._name
91 def __call__(self, value=None):
92 if value == None:
93 return self.get()
94 else:
95 self.set(value)
96 def set(self, value):
97 return self._tk.setvar(self._name, value)
98
99class StringVar(Variable):
100 def __init__(self, master=None):
101 Variable.__init__(self, master)
102 def get(self):
103 return self._tk.getvar(self._name)
104
105class IntVar(Variable):
106 def __init__(self, master=None):
107 Variable.__init__(self, master)
108 def get(self):
109 return self._tk.getint(self._tk.getvar(self._name))
110
111class DoubleVar(Variable):
112 def __init__(self, master=None):
113 Variable.__init__(self, master)
114 def get(self):
115 return self._tk.getdouble(self._tk.getvar(self._name))
116
117class BooleanVar(Variable):
118 def __init__(self, master=None):
119 Variable.__init__(self, master)
120 def get(self):
121 return self._tk.getboolean(self._tk.getvar(self._name))
122
Guido van Rossum35f67fb1995-08-04 03:50:29 +0000123def mainloop(n=0):
124 _default_root.tk.mainloop(n)
Guido van Rossum2dcf5291994-07-06 09:23:20 +0000125
126def getint(s):
127 return _default_root.tk.getint(s)
128
129def getdouble(s):
130 return _default_root.tk.getdouble(s)
131
132def getboolean(s):
133 return _default_root.tk.getboolean(s)
134
Guido van Rossum18468821994-06-20 07:49:28 +0000135class Misc:
136 def tk_strictMotif(self, boolean=None):
Guido van Rossum2dcf5291994-07-06 09:23:20 +0000137 return self.tk.getboolean(self.tk.call(
Guido van Rossum18468821994-06-20 07:49:28 +0000138 'set', 'tk_strictMotif', boolean))
Guido van Rossumaec5dc91994-06-27 07:55:12 +0000139 def tk_menuBar(self, *args):
140 apply(self.tk.call, ('tk_menuBar', self._w) + args)
Guido van Rossum2dcf5291994-07-06 09:23:20 +0000141 def wait_variable(self, name='PY_VAR'):
Guido van Rossum18468821994-06-20 07:49:28 +0000142 self.tk.call('tkwait', 'variable', name)
Guido van Rossum2dcf5291994-07-06 09:23:20 +0000143 waitvar = wait_variable # XXX b/w compat
Guido van Rossum9beb9321994-06-27 23:15:31 +0000144 def wait_window(self, window=None):
145 if window == None:
146 window = self
147 self.tk.call('tkwait', 'window', window._w)
148 def wait_visibility(self, window=None):
149 if window == None:
150 window = self
151 self.tk.call('tkwait', 'visibility', window._w)
Guido van Rossumaec5dc91994-06-27 07:55:12 +0000152 def setvar(self, name='PY_VAR', value='1'):
Guido van Rossum18468821994-06-20 07:49:28 +0000153 self.tk.setvar(name, value)
Guido van Rossumaec5dc91994-06-27 07:55:12 +0000154 def getvar(self, name='PY_VAR'):
Guido van Rossum5e8d3721994-06-20 08:12:01 +0000155 return self.tk.getvar(name)
156 def getint(self, s):
157 return self.tk.getint(s)
Guido van Rossum1e9e4001994-06-20 09:09:51 +0000158 def getdouble(self, s):
159 return self.tk.getdouble(s)
160 def getboolean(self, s):
161 return self.tk.getboolean(s)
Guido van Rossum45853db1994-06-20 12:19:19 +0000162 def focus_set(self):
Guido van Rossum18468821994-06-20 07:49:28 +0000163 self.tk.call('focus', self._w)
Guido van Rossum45853db1994-06-20 12:19:19 +0000164 focus = focus_set # XXX b/w compat?
165 def focus_default_set(self):
Guido van Rossum18468821994-06-20 07:49:28 +0000166 self.tk.call('focus', 'default', self._w)
Guido van Rossum45853db1994-06-20 12:19:19 +0000167 def focus_default_none(self):
168 self.tk.call('focus', 'default', 'none')
169 focus_default = focus_default_set
Guido van Rossum18468821994-06-20 07:49:28 +0000170 def focus_none(self):
171 self.tk.call('focus', 'none')
Guido van Rossum45853db1994-06-20 12:19:19 +0000172 def focus_get(self):
173 name = self.tk.call('focus')
174 if name == 'none': return None
175 return self._nametowidget(name)
Guido van Rossum18468821994-06-20 07:49:28 +0000176 def after(self, ms, func=None, *args):
177 if not func:
Guido van Rossum96ebbd31995-09-30 17:05:26 +0000178 # I'd rather use time.sleep(ms*0.001)
Guido van Rossum18468821994-06-20 07:49:28 +0000179 self.tk.call('after', ms)
180 else:
Guido van Rossum08a40381994-06-21 11:44:21 +0000181 # XXX Disgusting hack to clean up after calling func
182 tmp = []
183 def callit(func=func, args=args, tk=self.tk, tmp=tmp):
184 try:
185 apply(func, args)
186 finally:
187 tk.deletecommand(tmp[0])
188 name = self._register(callit)
189 tmp.append(name)
Guido van Rossum96ebbd31995-09-30 17:05:26 +0000190 return self.tk.call('after', ms, name)
191 def after_idle(self, func, *args):
192 return apply(self.after, ('idle', func) + args)
193 def after_cancel(self, id):
194 self.tk.call('after', 'cancel', id)
Guido van Rossum35f67fb1995-08-04 03:50:29 +0000195 def bell(self, displayof=None):
196 if displayof:
197 self.tk.call('bell', '-displayof', displayof)
198 else:
199 self.tk.call('bell', '-displayof', self._w)
Guido van Rossum45853db1994-06-20 12:19:19 +0000200 # XXX grab current w/o window argument
201 def grab_current(self):
202 name = self.tk.call('grab', 'current', self._w)
203 if not name: return None
204 return self._nametowidget(name)
Guido van Rossum18468821994-06-20 07:49:28 +0000205 def grab_release(self):
206 self.tk.call('grab', 'release', self._w)
207 def grab_set(self):
208 self.tk.call('grab', 'set', self._w)
209 def grab_set_global(self):
210 self.tk.call('grab', 'set', '-global', self._w)
211 def grab_status(self):
Guido van Rossum45853db1994-06-20 12:19:19 +0000212 status = self.tk.call('grab', 'status', self._w)
213 if status == 'none': status = None
214 return status
Guido van Rossum18468821994-06-20 07:49:28 +0000215 def lower(self, belowThis=None):
216 self.tk.call('lower', self._w, belowThis)
Guido van Rossum780044f1994-10-20 22:02:27 +0000217 def option_add(self, pattern, value, priority = None):
Guido van Rossum96ebbd31995-09-30 17:05:26 +0000218 self.tk.call('option', 'add', pattern, value, priority)
Guido van Rossum780044f1994-10-20 22:02:27 +0000219 def option_clear(self):
220 self.tk.call('option', 'clear')
221 def option_get(self, name, className):
222 return self.tk.call('option', 'get', self._w, name, className)
223 def option_readfile(self, fileName, priority = None):
224 self.tk.call('option', 'readfile', fileName, priority)
Guido van Rossum18468821994-06-20 07:49:28 +0000225 def selection_clear(self):
226 self.tk.call('selection', 'clear', self._w)
227 def selection_get(self, type=None):
Guido van Rossumbd84b041994-07-04 10:48:25 +0000228 return self.tk.call('selection', 'get', type)
Guido van Rossum18468821994-06-20 07:49:28 +0000229 def selection_handle(self, func, type=None, format=None):
230 name = self._register(func)
Guido van Rossumaec5dc91994-06-27 07:55:12 +0000231 self.tk.call('selection', 'handle', self._w,
232 name, type, format)
233 def selection_own(self, func=None):
234 name = self._register(func)
235 self.tk.call('selection', 'own', self._w, name)
236 def selection_own_get(self):
237 return self._nametowidget(self.tk.call('selection', 'own'))
238 def send(self, interp, cmd, *args):
Guido van Rossum18468821994-06-20 07:49:28 +0000239 return apply(self.tk.call, ('send', interp, cmd) + args)
Guido van Rossum5e8d3721994-06-20 08:12:01 +0000240 def lower(self, belowThis=None):
241 self.tk.call('lift', self._w, belowThis)
242 def tkraise(self, aboveThis=None):
243 self.tk.call('raise', self._w, aboveThis)
244 lift = tkraise
Guido van Rossum18468821994-06-20 07:49:28 +0000245 def colormodel(self, value=None):
246 return self.tk.call('tk', 'colormodel', self._w, value)
247 def winfo_atom(self, name):
248 return self.tk.getint(self.tk.call('winfo', 'atom', name))
249 def winfo_atomname(self, id):
250 return self.tk.call('winfo', 'atomname', id)
251 def winfo_cells(self):
252 return self.tk.getint(
253 self.tk.call('winfo', 'cells', self._w))
Guido van Rossum45853db1994-06-20 12:19:19 +0000254 def winfo_children(self):
255 return map(self._nametowidget,
256 self.tk.splitlist(self.tk.call(
257 'winfo', 'children', self._w)))
Guido van Rossum18468821994-06-20 07:49:28 +0000258 def winfo_class(self):
259 return self.tk.call('winfo', 'class', self._w)
260 def winfo_containing(self, rootX, rootY):
261 return self.tk.call('winfo', 'containing', rootx, rootY)
262 def winfo_depth(self):
263 return self.tk.getint(self.tk.call('winfo', 'depth', self._w))
264 def winfo_exists(self):
265 return self.tk.getint(
266 self.tk.call('winfo', 'exists', self._w))
267 def winfo_fpixels(self, number):
268 return self.tk.getdouble(self.tk.call(
269 'winfo', 'fpixels', self._w, number))
270 def winfo_geometry(self):
271 return self.tk.call('winfo', 'geometry', self._w)
272 def winfo_height(self):
273 return self.tk.getint(
274 self.tk.call('winfo', 'height', self._w))
275 def winfo_id(self):
276 return self.tk.getint(
277 self.tk.call('winfo', 'id', self._w))
278 def winfo_interps(self):
279 return self.tk.splitlist(
280 self.tk.call('winfo', 'interps'))
281 def winfo_ismapped(self):
282 return self.tk.getint(
283 self.tk.call('winfo', 'ismapped', self._w))
284 def winfo_name(self):
285 return self.tk.call('winfo', 'name', self._w)
286 def winfo_parent(self):
287 return self.tk.call('winfo', 'parent', self._w)
288 def winfo_pathname(self, id):
289 return self.tk.call('winfo', 'pathname', id)
290 def winfo_pixels(self, number):
291 return self.tk.getint(
292 self.tk.call('winfo', 'pixels', self._w, number))
293 def winfo_reqheight(self):
294 return self.tk.getint(
295 self.tk.call('winfo', 'reqheight', self._w))
296 def winfo_reqwidth(self):
297 return self.tk.getint(
298 self.tk.call('winfo', 'reqwidth', self._w))
299 def winfo_rgb(self, color):
300 return self._getints(
301 self.tk.call('winfo', 'rgb', self._w, color))
302 def winfo_rootx(self):
303 return self.tk.getint(
304 self.tk.call('winfo', 'rootx', self._w))
305 def winfo_rooty(self):
306 return self.tk.getint(
307 self.tk.call('winfo', 'rooty', self._w))
308 def winfo_screen(self):
309 return self.tk.call('winfo', 'screen', self._w)
310 def winfo_screencells(self):
311 return self.tk.getint(
312 self.tk.call('winfo', 'screencells', self._w))
313 def winfo_screendepth(self):
314 return self.tk.getint(
315 self.tk.call('winfo', 'screendepth', self._w))
316 def winfo_screenheight(self):
317 return self.tk.getint(
318 self.tk.call('winfo', 'screenheight', self._w))
319 def winfo_screenmmheight(self):
320 return self.tk.getint(
321 self.tk.call('winfo', 'screenmmheight', self._w))
322 def winfo_screenmmwidth(self):
323 return self.tk.getint(
324 self.tk.call('winfo', 'screenmmwidth', self._w))
325 def winfo_screenvisual(self):
326 return self.tk.call('winfo', 'screenvisual', self._w)
327 def winfo_screenwidth(self):
328 return self.tk.getint(
329 self.tk.call('winfo', 'screenwidth', self._w))
330 def winfo_toplevel(self):
Guido van Rossumaec5dc91994-06-27 07:55:12 +0000331 return self._nametowidget(self.tk.call(
332 'winfo', 'toplevel', self._w))
Guido van Rossum18468821994-06-20 07:49:28 +0000333 def winfo_visual(self):
334 return self.tk.call('winfo', 'visual', self._w)
335 def winfo_vrootheight(self):
336 return self.tk.getint(
337 self.tk.call('winfo', 'vrootheight', self._w))
338 def winfo_vrootwidth(self):
339 return self.tk.getint(
340 self.tk.call('winfo', 'vrootwidth', self._w))
341 def winfo_vrootx(self):
342 return self.tk.getint(
343 self.tk.call('winfo', 'vrootx', self._w))
344 def winfo_vrooty(self):
345 return self.tk.getint(
346 self.tk.call('winfo', 'vrooty', self._w))
347 def winfo_width(self):
348 return self.tk.getint(
349 self.tk.call('winfo', 'width', self._w))
350 def winfo_x(self):
351 return self.tk.getint(
352 self.tk.call('winfo', 'x', self._w))
353 def winfo_y(self):
354 return self.tk.getint(
355 self.tk.call('winfo', 'y', self._w))
356 def update(self):
357 self.tk.call('update')
358 def update_idletasks(self):
359 self.tk.call('update', 'idletasks')
Guido van Rossum761c5ab1995-07-14 15:29:10 +0000360 def bind(self, sequence, func=None, add=''):
361 if add: add = '+'
362 if func:
363 name = self._register(func, self._substitute)
364 self.tk.call('bind', self._w, sequence,
365 (add + name,) + self._subst_format)
366 else:
367 return self.tk.call('bind', self._w, sequence)
Guido van Rossumef8f8811994-08-08 12:47:33 +0000368 def unbind(self, sequence):
369 self.tk.call('bind', self._w, sequence, '')
Guido van Rossum761c5ab1995-07-14 15:29:10 +0000370 def bind_all(self, sequence, func=None, add=''):
Guido van Rossum18468821994-06-20 07:49:28 +0000371 if add: add = '+'
Guido van Rossum761c5ab1995-07-14 15:29:10 +0000372 if func:
373 name = self._register(func, self._substitute)
374 self.tk.call('bind', 'all' , sequence,
375 (add + name,) + self._subst_format)
376 else:
377 return self.tk.call('bind', 'all', sequence)
378 def unbind_all(self, sequence):
379 self.tk.call('bind', 'all' , sequence, '')
380 def bind_class(self, className, sequence, func=None, add=''):
Guido van Rossum18468821994-06-20 07:49:28 +0000381 if add: add = '+'
Guido van Rossum761c5ab1995-07-14 15:29:10 +0000382 if func:
383 name = self._register(func, self._substitute)
384 self.tk.call('bind', className , sequence,
385 (add + name,) + self._subst_format)
386 else:
387 return self.tk.call('bind', className, sequence)
388 def unbind_class(self, className, sequence):
389 self.tk.call('bind', className , sequence, '')
Guido van Rossum35f67fb1995-08-04 03:50:29 +0000390 def mainloop(self, n=0):
391 self.tk.mainloop(n)
Guido van Rossum18468821994-06-20 07:49:28 +0000392 def quit(self):
393 self.tk.quit()
Guido van Rossum18468821994-06-20 07:49:28 +0000394 def _getints(self, string):
Guido van Rossum45853db1994-06-20 12:19:19 +0000395 if not string: return None
Guido van Rossum7e9394a1995-03-17 16:21:33 +0000396 return tuple(map(self.tk.getint, self.tk.splitlist(string)))
397 def _getdoubles(self, string):
398 if not string: return None
399 return tuple(map(self.tk.getdouble, self.tk.splitlist(string)))
Guido van Rossum18468821994-06-20 07:49:28 +0000400 def _getboolean(self, string):
401 if string:
402 return self.tk.getboolean(string)
Guido van Rossum35f67fb1995-08-04 03:50:29 +0000403 def _options(self, cnf, kw = None):
404 if kw:
405 cnf = _cnfmerge((cnf, kw))
406 else:
407 cnf = _cnfmerge(cnf)
Guido van Rossum18468821994-06-20 07:49:28 +0000408 res = ()
409 for k, v in cnf.items():
Guido van Rossuma5773dd1995-09-07 19:22:00 +0000410 if k[-1] == '_': k = k[:-1]
Guido van Rossum2dcf5291994-07-06 09:23:20 +0000411 if type(v) in CallableTypes:
Guido van Rossum18468821994-06-20 07:49:28 +0000412 v = self._register(v)
413 res = res + ('-'+k, v)
414 return res
Guido van Rossum45853db1994-06-20 12:19:19 +0000415 def _nametowidget(self, name):
416 w = self
417 if name[0] == '.':
418 w = w._root()
419 name = name[1:]
420 from string import find
421 while name:
422 i = find(name, '.')
423 if i >= 0:
424 name, tail = name[:i], name[i+1:]
425 else:
426 tail = ''
427 w = w.children[name]
428 name = tail
429 return w
Guido van Rossum18468821994-06-20 07:49:28 +0000430 def _register(self, func, subst=None):
Guido van Rossum71b1a901995-09-18 21:54:35 +0000431 f = self._wrap(func, subst)
Guido van Rossum18468821994-06-20 07:49:28 +0000432 name = `id(f)`
433 if hasattr(func, 'im_func'):
434 func = func.im_func
Guido van Rossuma5773dd1995-09-07 19:22:00 +0000435 if hasattr(func, '__name__') and \
436 type(func.__name__) == type(''):
437 name = name + func.__name__
Guido van Rossum18468821994-06-20 07:49:28 +0000438 self.tk.createcommand(name, f)
439 return name
Guido van Rossum9beb9321994-06-27 23:15:31 +0000440 register = _register
Guido van Rossum45853db1994-06-20 12:19:19 +0000441 def _root(self):
442 w = self
443 while w.master: w = w.master
444 return w
Guido van Rossumaec5dc91994-06-27 07:55:12 +0000445 _subst_format = ('%#', '%b', '%f', '%h', '%k',
Guido van Rossum45853db1994-06-20 12:19:19 +0000446 '%s', '%t', '%w', '%x', '%y',
447 '%A', '%E', '%K', '%N', '%W', '%T', '%X', '%Y')
448 def _substitute(self, *args):
449 tk = self.tk
Guido van Rossumaec5dc91994-06-27 07:55:12 +0000450 if len(args) != len(self._subst_format): return args
Guido van Rossum45853db1994-06-20 12:19:19 +0000451 nsign, b, f, h, k, s, t, w, x, y, A, E, K, N, W, T, X, Y = args
452 # Missing: (a, c, d, m, o, v, B, R)
453 e = Event()
454 e.serial = tk.getint(nsign)
455 e.num = tk.getint(b)
456 try: e.focus = tk.getboolean(f)
457 except TclError: pass
458 e.height = tk.getint(h)
459 e.keycode = tk.getint(k)
460 e.state = tk.getint(s)
461 e.time = tk.getint(t)
462 e.width = tk.getint(w)
463 e.x = tk.getint(x)
464 e.y = tk.getint(y)
465 e.char = A
466 try: e.send_event = tk.getboolean(E)
467 except TclError: pass
468 e.keysym = K
469 e.keysym_num = tk.getint(N)
470 e.type = T
471 e.widget = self._nametowidget(W)
472 e.x_root = tk.getint(X)
473 e.y_root = tk.getint(Y)
474 return (e,)
Guido van Rossuma5773dd1995-09-07 19:22:00 +0000475 def _report_exception(self):
476 import sys
477 exc, val, tb = sys.exc_type, sys.exc_value, sys.exc_traceback
478 root = self._root()
479 root.report_callback_exception(exc, val, tb)
Guido van Rossum71b1a901995-09-18 21:54:35 +0000480 def _wrap(self, func, subst=None):
481 return CallWrapper(func, subst, self).__call__
Guido van Rossum18468821994-06-20 07:49:28 +0000482
Guido van Rossuma5773dd1995-09-07 19:22:00 +0000483class CallWrapper:
484 def __init__(self, func, subst, widget):
Guido van Rossum18468821994-06-20 07:49:28 +0000485 self.func = func
486 self.subst = subst
Guido van Rossuma5773dd1995-09-07 19:22:00 +0000487 self.widget = widget
Guido van Rossum18468821994-06-20 07:49:28 +0000488 def __call__(self, *args):
Guido van Rossum18468821994-06-20 07:49:28 +0000489 try:
Guido van Rossuma5773dd1995-09-07 19:22:00 +0000490 if self.subst:
491 args = apply(self.subst, args)
492 return apply(self.func, args)
Guido van Rossum45853db1994-06-20 12:19:19 +0000493 except SystemExit, msg:
494 raise SystemExit, msg
Guido van Rossum18468821994-06-20 07:49:28 +0000495 except:
Guido van Rossuma5773dd1995-09-07 19:22:00 +0000496 self.widget._report_exception()
Guido van Rossum18468821994-06-20 07:49:28 +0000497
498class Wm:
499 def aspect(self,
500 minNumer=None, minDenom=None,
501 maxNumer=None, maxDenom=None):
502 return self._getints(
503 self.tk.call('wm', 'aspect', self._w,
504 minNumer, minDenom,
505 maxNumer, maxDenom))
506 def client(self, name=None):
507 return self.tk.call('wm', 'client', self._w, name)
508 def command(self, value=None):
509 return self.tk.call('wm', 'command', self._w, value)
510 def deiconify(self):
511 return self.tk.call('wm', 'deiconify', self._w)
512 def focusmodel(self, model=None):
513 return self.tk.call('wm', 'focusmodel', self._w, model)
514 def frame(self):
515 return self.tk.call('wm', 'frame', self._w)
516 def geometry(self, newGeometry=None):
517 return self.tk.call('wm', 'geometry', self._w, newGeometry)
518 def grid(self,
519 baseWidht=None, baseHeight=None,
520 widthInc=None, heightInc=None):
521 return self._getints(self.tk.call(
522 'wm', 'grid', self._w,
523 baseWidht, baseHeight, widthInc, heightInc))
524 def group(self, pathName=None):
525 return self.tk.call('wm', 'group', self._w, pathName)
526 def iconbitmap(self, bitmap=None):
527 return self.tk.call('wm', 'iconbitmap', self._w, bitmap)
528 def iconify(self):
529 return self.tk.call('wm', 'iconify', self._w)
530 def iconmask(self, bitmap=None):
531 return self.tk.call('wm', 'iconmask', self._w, bitmap)
532 def iconname(self, newName=None):
533 return self.tk.call('wm', 'iconname', self._w, newName)
534 def iconposition(self, x=None, y=None):
535 return self._getints(self.tk.call(
536 'wm', 'iconposition', self._w, x, y))
537 def iconwindow(self, pathName=None):
538 return self.tk.call('wm', 'iconwindow', self._w, pathName)
539 def maxsize(self, width=None, height=None):
540 return self._getints(self.tk.call(
541 'wm', 'maxsize', self._w, width, height))
542 def minsize(self, width=None, height=None):
543 return self._getints(self.tk.call(
544 'wm', 'minsize', self._w, width, height))
545 def overrideredirect(self, boolean=None):
546 return self._getboolean(self.tk.call(
547 'wm', 'overrideredirect', self._w, boolean))
548 def positionfrom(self, who=None):
549 return self.tk.call('wm', 'positionfrom', self._w, who)
550 def protocol(self, name=None, func=None):
Guido van Rossum2dcf5291994-07-06 09:23:20 +0000551 if type(func) in CallableTypes:
Guido van Rossum18468821994-06-20 07:49:28 +0000552 command = self._register(func)
553 else:
554 command = func
555 return self.tk.call(
556 'wm', 'protocol', self._w, name, command)
557 def sizefrom(self, who=None):
558 return self.tk.call('wm', 'sizefrom', self._w, who)
559 def state(self):
560 return self.tk.call('wm', 'state', self._w)
561 def title(self, string=None):
562 return self.tk.call('wm', 'title', self._w, string)
563 def transient(self, master=None):
564 return self.tk.call('wm', 'transient', self._w, master)
565 def withdraw(self):
566 return self.tk.call('wm', 'withdraw', self._w)
567
568class Tk(Misc, Wm):
569 _w = '.'
570 def __init__(self, screenName=None, baseName=None, className='Tk'):
Guido van Rossuma5773dd1995-09-07 19:22:00 +0000571 global _default_root
Guido van Rossum45853db1994-06-20 12:19:19 +0000572 self.master = None
573 self.children = {}
Guido van Rossum18468821994-06-20 07:49:28 +0000574 if baseName is None:
575 import sys, os
576 baseName = os.path.basename(sys.argv[0])
577 if baseName[-3:] == '.py': baseName = baseName[:-3]
578 self.tk = tkinter.create(screenName, baseName, className)
Guido van Rossumf7f79ac1995-10-07 19:08:37 +0000579 # Version sanity checks
580 tk_version = self.tk.getvar('tk_version')
581 if tk_version != tkinter.TK_VERSION:
582 raise RuntimeError, \
583 "tk.h version (%s) doesn't match libtk.a version (%s)" \
584 % (tkinter.TK_VERSION, tk_version)
585 tcl_version = self.tk.getvar('tcl_version')
586 if tcl_version != tkinter.TCL_VERSION:
587 raise RuntimeError, \
588 "tcl.h version (%s) doesn't match libtcl.a version (%s)" \
589 % (tkinter.TCL_VERSION, tcl_version)
590 if TkVersion < 4.0:
591 raise RuntimeError, \
592 "Tk 4.0 or higher is required; found Tk %s" \
593 % str(TkVersion)
Guido van Rossum45853db1994-06-20 12:19:19 +0000594 self.tk.createcommand('tkerror', _tkerror)
Guido van Rossum97aeca11994-07-07 13:12:12 +0000595 self.tk.createcommand('exit', _exit)
Guido van Rossum27b77a41994-07-12 15:52:32 +0000596 self.readprofile(baseName, className)
Guido van Rossuma5773dd1995-09-07 19:22:00 +0000597 if not _default_root:
598 _default_root = self
Guido van Rossum45853db1994-06-20 12:19:19 +0000599 def destroy(self):
600 for c in self.children.values(): c.destroy()
Guido van Rossum45853db1994-06-20 12:19:19 +0000601 self.tk.call('destroy', self._w)
Guido van Rossum18468821994-06-20 07:49:28 +0000602 def __str__(self):
Guido van Rossum45853db1994-06-20 12:19:19 +0000603 return self._w
Guido van Rossum27b77a41994-07-12 15:52:32 +0000604 def readprofile(self, baseName, className):
Guido van Rossum35f67fb1995-08-04 03:50:29 +0000605 ##print __import__
606 import os, pdb
Guido van Rossum27b77a41994-07-12 15:52:32 +0000607 if os.environ.has_key('HOME'): home = os.environ['HOME']
608 else: home = os.curdir
609 class_tcl = os.path.join(home, '.%s.tcl' % className)
610 class_py = os.path.join(home, '.%s.py' % className)
611 base_tcl = os.path.join(home, '.%s.tcl' % baseName)
612 base_py = os.path.join(home, '.%s.py' % baseName)
613 dir = {'self': self}
Guido van Rossum35f67fb1995-08-04 03:50:29 +0000614 ##pdb.run('from Tkinter import *', dir)
Guido van Rossum27b77a41994-07-12 15:52:32 +0000615 exec 'from Tkinter import *' in dir
616 if os.path.isfile(class_tcl):
617 print 'source', `class_tcl`
618 self.tk.call('source', class_tcl)
619 if os.path.isfile(class_py):
620 print 'execfile', `class_py`
621 execfile(class_py, dir)
622 if os.path.isfile(base_tcl):
623 print 'source', `base_tcl`
624 self.tk.call('source', base_tcl)
625 if os.path.isfile(base_py):
626 print 'execfile', `base_py`
627 execfile(base_py, dir)
Guido van Rossuma5773dd1995-09-07 19:22:00 +0000628 def report_callback_exception(self, exc, val, tb):
629 import traceback
630 print "Exception in Tkinter callback"
631 traceback.print_exception(exc, val, tb)
Guido van Rossum18468821994-06-20 07:49:28 +0000632
633class Pack:
Guido van Rossum35f67fb1995-08-04 03:50:29 +0000634 def config(self, cnf={}, **kw):
Guido van Rossum18468821994-06-20 07:49:28 +0000635 apply(self.tk.call,
636 ('pack', 'configure', self._w)
Guido van Rossum35f67fb1995-08-04 03:50:29 +0000637 + self._options(cnf, kw))
Guido van Rossum18468821994-06-20 07:49:28 +0000638 pack = config
639 def __setitem__(self, key, value):
640 Pack.config({key: value})
641 def forget(self):
642 self.tk.call('pack', 'forget', self._w)
643 def newinfo(self):
Guido van Rossum69170c51994-07-11 15:21:31 +0000644 words = self.tk.splitlist(
645 self.tk.call('pack', 'newinfo', self._w))
646 dict = {}
647 for i in range(0, len(words), 2):
648 key = words[i][1:]
649 value = words[i+1]
650 if value[0] == '.':
651 value = self._nametowidget(value)
652 dict[key] = value
653 return dict
Guido van Rossum18468821994-06-20 07:49:28 +0000654 info = newinfo
Guido van Rossum5505d561994-12-30 17:16:35 +0000655 _noarg_ = ['_noarg_']
656 def propagate(self, flag=_noarg_):
Guido van Rossuma5773dd1995-09-07 19:22:00 +0000657 if flag is Pack._noarg_:
Guido van Rossum18468821994-06-20 07:49:28 +0000658 return self._getboolean(self.tk.call(
659 'pack', 'propagate', self._w))
Guido van Rossum5505d561994-12-30 17:16:35 +0000660 else:
661 self.tk.call('pack', 'propagate', self._w, flag)
Guido van Rossum18468821994-06-20 07:49:28 +0000662 def slaves(self):
Guido van Rossum45853db1994-06-20 12:19:19 +0000663 return map(self._nametowidget,
664 self.tk.splitlist(
665 self.tk.call('pack', 'slaves', self._w)))
Guido van Rossum18468821994-06-20 07:49:28 +0000666
667class Place:
Guido van Rossum35f67fb1995-08-04 03:50:29 +0000668 def config(self, cnf={}, **kw):
Guido van Rossum18468821994-06-20 07:49:28 +0000669 apply(self.tk.call,
670 ('place', 'configure', self._w)
Guido van Rossum35f67fb1995-08-04 03:50:29 +0000671 + self._options(cnf, kw))
Guido van Rossum18468821994-06-20 07:49:28 +0000672 place = config
673 def __setitem__(self, key, value):
674 Place.config({key: value})
675 def forget(self):
676 self.tk.call('place', 'forget', self._w)
677 def info(self):
678 return self.tk.call('place', 'info', self._w)
679 def slaves(self):
Guido van Rossum45853db1994-06-20 12:19:19 +0000680 return map(self._nametowidget,
681 self.tk.splitlist(
682 self.tk.call(
683 'place', 'slaves', self._w)))
Guido van Rossum18468821994-06-20 07:49:28 +0000684
Guido van Rossum18468821994-06-20 07:49:28 +0000685class Widget(Misc, Pack, Place):
Guido van Rossumaec5dc91994-06-27 07:55:12 +0000686 def _setup(self, master, cnf):
Guido van Rossum45853db1994-06-20 12:19:19 +0000687 global _default_root
Guido van Rossum18468821994-06-20 07:49:28 +0000688 if not master:
Guido van Rossum45853db1994-06-20 12:19:19 +0000689 if not _default_root:
690 _default_root = Tk()
691 master = _default_root
692 if not _default_root:
693 _default_root = master
Guido van Rossum18468821994-06-20 07:49:28 +0000694 self.master = master
695 self.tk = master.tk
696 if cnf.has_key('name'):
697 name = cnf['name']
698 del cnf['name']
699 else:
700 name = `id(self)`
Guido van Rossum45853db1994-06-20 12:19:19 +0000701 self._name = name
Guido van Rossum35f67fb1995-08-04 03:50:29 +0000702 if master._w=='.':
Guido van Rossum18468821994-06-20 07:49:28 +0000703 self._w = '.' + name
704 else:
705 self._w = master._w + '.' + name
Guido van Rossumaec5dc91994-06-27 07:55:12 +0000706 self.children = {}
707 if self.master.children.has_key(self._name):
Guido van Rossum2dcf5291994-07-06 09:23:20 +0000708 self.master.children[self._name].destroy()
Guido van Rossumaec5dc91994-06-27 07:55:12 +0000709 self.master.children[self._name] = self
Guido van Rossum35f67fb1995-08-04 03:50:29 +0000710 def __init__(self, master, widgetName, cnf={}, kw={}, extra=()):
711 if kw:
712 cnf = _cnfmerge((cnf, kw))
Guido van Rossum18468821994-06-20 07:49:28 +0000713 self.widgetName = widgetName
Guido van Rossum761c5ab1995-07-14 15:29:10 +0000714 Widget._setup(self, master, cnf)
Guido van Rossumbf4d8f91995-09-01 20:35:37 +0000715 apply(self.tk.call, (widgetName, self._w)+extra)
Guido van Rossumef8f8811994-08-08 12:47:33 +0000716 if cnf:
717 Widget.config(self, cnf)
Guido van Rossum35f67fb1995-08-04 03:50:29 +0000718 def config(self, cnf=None, **kw):
719 # XXX ought to generalize this so tag_config etc. can use it
720 if kw:
721 cnf = _cnfmerge((cnf, kw))
722 else:
723 cnf = _cnfmerge(cnf)
Guido van Rossum9b68fd91994-06-23 07:40:14 +0000724 if cnf is None:
725 cnf = {}
726 for x in self.tk.split(
727 self.tk.call(self._w, 'configure')):
728 cnf[x[0][1:]] = (x[0][1:],) + x[1:]
729 return cnf
730 if type(cnf) == StringType:
731 x = self.tk.split(self.tk.call(
732 self._w, 'configure', '-'+cnf))
733 return (x[0][1:],) + x[1:]
Guido van Rossum18468821994-06-20 07:49:28 +0000734 for k in cnf.keys():
735 if type(k) == ClassType:
736 k.config(self, cnf[k])
737 del cnf[k]
738 apply(self.tk.call, (self._w, 'configure')
739 + self._options(cnf))
740 def __getitem__(self, key):
Guido van Rossum761c5ab1995-07-14 15:29:10 +0000741 if TkVersion >= 4.0:
742 return self.tk.call(self._w, 'cget', '-' + key)
Guido van Rossum535cf0c1994-06-27 07:55:59 +0000743 v = self.tk.splitlist(self.tk.call(
Guido van Rossum18468821994-06-20 07:49:28 +0000744 self._w, 'configure', '-' + key))
745 return v[4]
746 def __setitem__(self, key, value):
747 Widget.config(self, {key: value})
Guido van Rossum9b68fd91994-06-23 07:40:14 +0000748 def keys(self):
749 return map(lambda x: x[0][1:],
750 self.tk.split(self.tk.call(self._w, 'configure')))
Guido van Rossum18468821994-06-20 07:49:28 +0000751 def __str__(self):
752 return self._w
Guido van Rossum45853db1994-06-20 12:19:19 +0000753 def destroy(self):
754 for c in self.children.values(): c.destroy()
Guido van Rossumf023ab01994-08-30 12:13:44 +0000755 if self.master.children.has_key(self._name):
756 del self.master.children[self._name]
Guido van Rossum18468821994-06-20 07:49:28 +0000757 self.tk.call('destroy', self._w)
Guido van Rossum18468821994-06-20 07:49:28 +0000758 def _do(self, name, args=()):
Guido van Rossum761c5ab1995-07-14 15:29:10 +0000759 return apply(self.tk.call, (self._w, name) + args)
Guido van Rossumf7f79ac1995-10-07 19:08:37 +0000760 # XXX The following method seems out of place here
761## def unbind_class(self, seq):
762## Misc.unbind_class(self, self.widgetName, seq)
Guido van Rossum18468821994-06-20 07:49:28 +0000763
764class Toplevel(Widget, Wm):
Guido van Rossum35f67fb1995-08-04 03:50:29 +0000765 def __init__(self, master=None, cnf={}, **kw):
766 if kw:
767 cnf = _cnfmerge((cnf, kw))
Guido van Rossum18468821994-06-20 07:49:28 +0000768 extra = ()
769 if cnf.has_key('screen'):
770 extra = ('-screen', cnf['screen'])
771 del cnf['screen']
772 if cnf.has_key('class'):
773 extra = extra + ('-class', cnf['class'])
774 del cnf['class']
Guido van Rossum35f67fb1995-08-04 03:50:29 +0000775 Widget.__init__(self, master, 'toplevel', cnf, {}, extra)
Guido van Rossum45853db1994-06-20 12:19:19 +0000776 root = self._root()
777 self.iconname(root.iconname())
778 self.title(root.title())
Guido van Rossum18468821994-06-20 07:49:28 +0000779
780class Button(Widget):
Guido van Rossum35f67fb1995-08-04 03:50:29 +0000781 def __init__(self, master=None, cnf={}, **kw):
782 Widget.__init__(self, master, 'button', cnf, kw)
Guido van Rossum761c5ab1995-07-14 15:29:10 +0000783 def tkButtonEnter(self, *dummy):
784 self.tk.call('tkButtonEnter', self._w)
785 def tkButtonLeave(self, *dummy):
786 self.tk.call('tkButtonLeave', self._w)
787 def tkButtonDown(self, *dummy):
788 self.tk.call('tkButtonDown', self._w)
789 def tkButtonUp(self, *dummy):
790 self.tk.call('tkButtonUp', self._w)
Guido van Rossum18468821994-06-20 07:49:28 +0000791 def flash(self):
792 self.tk.call(self._w, 'flash')
793 def invoke(self):
794 self.tk.call(self._w, 'invoke')
795
796# Indices:
Guido van Rossum35f67fb1995-08-04 03:50:29 +0000797# XXX I don't like these -- take them away
Guido van Rossum18468821994-06-20 07:49:28 +0000798def AtEnd():
799 return 'end'
Guido van Rossum1e9e4001994-06-20 09:09:51 +0000800def AtInsert(*args):
801 s = 'insert'
802 for a in args:
803 if a: s = s + (' ' + a)
804 return s
Guido van Rossum18468821994-06-20 07:49:28 +0000805def AtSelFirst():
806 return 'sel.first'
807def AtSelLast():
808 return 'sel.last'
809def At(x, y=None):
Guido van Rossum5e0c25b1994-07-12 09:04:41 +0000810 if y is None:
811 return '@' + `x`
Guido van Rossum18468821994-06-20 07:49:28 +0000812 else:
Guido van Rossum5e0c25b1994-07-12 09:04:41 +0000813 return '@' + `x` + ',' + `y`
Guido van Rossum18468821994-06-20 07:49:28 +0000814
815class Canvas(Widget):
Guido van Rossum35f67fb1995-08-04 03:50:29 +0000816 def __init__(self, master=None, cnf={}, **kw):
817 Widget.__init__(self, master, 'canvas', cnf, kw)
Guido van Rossum18468821994-06-20 07:49:28 +0000818 def addtag(self, *args):
819 self._do('addtag', args)
Guido van Rossum9b68fd91994-06-23 07:40:14 +0000820 def addtag_above(self, tagOrId):
821 self.addtag('above', tagOrId)
822 def addtag_all(self):
823 self.addtag('all')
824 def addtag_below(self, tagOrId):
825 self.addtag('below', tagOrId)
826 def addtag_closest(self, x, y, halo=None, start=None):
827 self.addtag('closest', x, y, halo, start)
828 def addtag_enclosed(self, x1, y1, x2, y2):
829 self.addtag('enclosed', x1, y1, x2, y2)
830 def addtag_overlapping(self, x1, y1, x2, y2):
831 self.addtag('overlapping', x1, y1, x2, y2)
832 def addtag_withtag(self, tagOrId):
833 self.addtag('withtag', tagOrId)
Guido van Rossum18468821994-06-20 07:49:28 +0000834 def bbox(self, *args):
Guido van Rossum9b68fd91994-06-23 07:40:14 +0000835 return self._getints(self._do('bbox', args)) or None
Guido van Rossumef8f8811994-08-08 12:47:33 +0000836 def tag_unbind(self, tagOrId, sequence):
837 self.tk.call(self._w, 'bind', tagOrId, sequence, '')
838 def tag_bind(self, tagOrId, sequence, func, add=''):
Guido van Rossum18468821994-06-20 07:49:28 +0000839 if add: add='+'
Guido van Rossum45853db1994-06-20 12:19:19 +0000840 name = self._register(func, self._substitute)
Guido van Rossum18468821994-06-20 07:49:28 +0000841 self.tk.call(self._w, 'bind', tagOrId, sequence,
Guido van Rossumaec5dc91994-06-27 07:55:12 +0000842 (add + name,) + self._subst_format)
Guido van Rossum18468821994-06-20 07:49:28 +0000843 def canvasx(self, screenx, gridspacing=None):
Guido van Rossum761c5ab1995-07-14 15:29:10 +0000844 return self.tk.getdouble(self.tk.call(
Guido van Rossum18468821994-06-20 07:49:28 +0000845 self._w, 'canvasx', screenx, gridspacing))
846 def canvasy(self, screeny, gridspacing=None):
Guido van Rossum761c5ab1995-07-14 15:29:10 +0000847 return self.tk.getdouble(self.tk.call(
Guido van Rossum18468821994-06-20 07:49:28 +0000848 self._w, 'canvasy', screeny, gridspacing))
849 def coords(self, *args):
850 return self._do('coords', args)
Guido van Rossum35f67fb1995-08-04 03:50:29 +0000851 def _create(self, itemType, args, kw): # Args: (value, value, ..., cnf={})
Guido van Rossum08a40381994-06-21 11:44:21 +0000852 args = _flatten(args)
Guido van Rossum18468821994-06-20 07:49:28 +0000853 cnf = args[-1]
Guido van Rossum2dcf5291994-07-06 09:23:20 +0000854 if type(cnf) in (DictionaryType, TupleType):
Guido van Rossum18468821994-06-20 07:49:28 +0000855 args = args[:-1]
856 else:
857 cnf = {}
Guido van Rossum2dcf5291994-07-06 09:23:20 +0000858 return self.tk.getint(apply(
859 self.tk.call,
860 (self._w, 'create', itemType)
Guido van Rossum35f67fb1995-08-04 03:50:29 +0000861 + args + self._options(cnf, kw)))
862 def create_arc(self, *args, **kw):
863 return self._create('arc', args, kw)
864 def create_bitmap(self, *args, **kw):
865 return self._create('bitmap', args, kw)
866 def create_image(self, *args, **kw):
867 return self._create('image', args, kw)
868 def create_line(self, *args, **kw):
869 return self._create('line', args, kw)
870 def create_oval(self, *args, **kw):
871 return self._create('oval', args, kw)
872 def create_polygon(self, *args, **kw):
873 return self._create('polygon', args, kw)
874 def create_rectangle(self, *args, **kw):
875 return self._create('rectangle', args, kw)
876 def create_text(self, *args, **kw):
877 return self._create('text', args, kw)
878 def create_window(self, *args, **kw):
879 return self._create('window', args, kw)
Guido van Rossum18468821994-06-20 07:49:28 +0000880 def dchars(self, *args):
881 self._do('dchars', args)
882 def delete(self, *args):
883 self._do('delete', args)
884 def dtag(self, *args):
885 self._do('dtag', args)
886 def find(self, *args):
Guido van Rossum08a40381994-06-21 11:44:21 +0000887 return self._getints(self._do('find', args))
Guido van Rossum9b68fd91994-06-23 07:40:14 +0000888 def find_above(self, tagOrId):
889 return self.find('above', tagOrId)
890 def find_all(self):
891 return self.find('all')
892 def find_below(self, tagOrId):
893 return self.find('below', tagOrId)
894 def find_closest(self, x, y, halo=None, start=None):
895 return self.find('closest', x, y, halo, start)
896 def find_enclosed(self, x1, y1, x2, y2):
897 return self.find('enclosed', x1, y1, x2, y2)
898 def find_overlapping(self, x1, y1, x2, y2):
899 return self.find('overlapping', x1, y1, x2, y2)
900 def find_withtag(self, tagOrId):
901 return self.find('withtag', tagOrId)
Guido van Rossum18468821994-06-20 07:49:28 +0000902 def focus(self, *args):
903 return self._do('focus', args)
904 def gettags(self, *args):
905 return self.tk.splitlist(self._do('gettags', args))
906 def icursor(self, *args):
907 self._do('icursor', args)
908 def index(self, *args):
909 return self.tk.getint(self._do('index', args))
910 def insert(self, *args):
911 self._do('insert', args)
Guido van Rossum35f67fb1995-08-04 03:50:29 +0000912 def itemconfig(self, tagOrId, cnf=None, **kw):
913 if cnf is None and not kw:
Guido van Rossum9b68fd91994-06-23 07:40:14 +0000914 cnf = {}
915 for x in self.tk.split(
916 self._do('itemconfigure', (tagOrId))):
917 cnf[x[0][1:]] = (x[0][1:],) + x[1:]
918 return cnf
Guido van Rossum35f67fb1995-08-04 03:50:29 +0000919 if type(cnf) == StringType and not kw:
Guido van Rossum9b68fd91994-06-23 07:40:14 +0000920 x = self.tk.split(self._do('itemconfigure',
921 (tagOrId, '-'+cnf,)))
922 return (x[0][1:],) + x[1:]
Guido van Rossum35f67fb1995-08-04 03:50:29 +0000923 self._do('itemconfigure', (tagOrId,)
924 + self._options(cnf, kw))
Guido van Rossum18468821994-06-20 07:49:28 +0000925 def lower(self, *args):
926 self._do('lower', args)
927 def move(self, *args):
928 self._do('move', args)
Guido van Rossum35f67fb1995-08-04 03:50:29 +0000929 def postscript(self, cnf={}, **kw):
930 return self._do('postscript', self._options(cnf, kw))
Guido van Rossum18468821994-06-20 07:49:28 +0000931 def tkraise(self, *args):
932 self._do('raise', args)
Guido van Rossum5e8d3721994-06-20 08:12:01 +0000933 lift = tkraise
Guido van Rossum18468821994-06-20 07:49:28 +0000934 def scale(self, *args):
935 self._do('scale', args)
936 def scan_mark(self, x, y):
937 self.tk.call(self._w, 'scan', 'mark', x, y)
938 def scan_dragto(self, x, y):
939 self.tk.call(self._w, 'scan', 'dragto', x, y)
940 def select_adjust(self, tagOrId, index):
Guido van Rossum08a40381994-06-21 11:44:21 +0000941 self.tk.call(self._w, 'select', 'adjust', tagOrId, index)
Guido van Rossum18468821994-06-20 07:49:28 +0000942 def select_clear(self):
Guido van Rossum761c5ab1995-07-14 15:29:10 +0000943 self.tk.call(self._w, 'select', 'clear', 'end')
Guido van Rossum18468821994-06-20 07:49:28 +0000944 def select_from(self, tagOrId, index):
Guido van Rossum761c5ab1995-07-14 15:29:10 +0000945 self.tk.call(self._w, 'select', 'set', tagOrId, index)
Guido van Rossum18468821994-06-20 07:49:28 +0000946 def select_item(self):
947 self.tk.call(self._w, 'select', 'item')
948 def select_to(self, tagOrId, index):
Guido van Rossum08a40381994-06-21 11:44:21 +0000949 self.tk.call(self._w, 'select', 'to', tagOrId, index)
Guido van Rossum18468821994-06-20 07:49:28 +0000950 def type(self, tagOrId):
Guido van Rossum08a40381994-06-21 11:44:21 +0000951 return self.tk.call(self._w, 'type', tagOrId) or None
Guido van Rossum761c5ab1995-07-14 15:29:10 +0000952 def xview(self, *args):
953 apply(self.tk.call, (self._w, 'xview')+args)
954 def yview(self, *args):
955 apply(self.tk.call, (self._w, 'yview')+args)
Guido van Rossum18468821994-06-20 07:49:28 +0000956
957class Checkbutton(Widget):
Guido van Rossum35f67fb1995-08-04 03:50:29 +0000958 def __init__(self, master=None, cnf={}, **kw):
959 Widget.__init__(self, master, 'checkbutton', cnf, kw)
Guido van Rossum18468821994-06-20 07:49:28 +0000960 def deselect(self):
961 self.tk.call(self._w, 'deselect')
962 def flash(self):
963 self.tk.call(self._w, 'flash')
964 def invoke(self):
965 self.tk.call(self._w, 'invoke')
966 def select(self):
967 self.tk.call(self._w, 'select')
968 def toggle(self):
969 self.tk.call(self._w, 'toggle')
970
971class Entry(Widget):
Guido van Rossum35f67fb1995-08-04 03:50:29 +0000972 def __init__(self, master=None, cnf={}, **kw):
973 Widget.__init__(self, master, 'entry', cnf, kw)
Guido van Rossum18468821994-06-20 07:49:28 +0000974 def tk_entryBackspace(self):
975 self.tk.call('tk_entryBackspace', self._w)
976 def tk_entryBackword(self):
977 self.tk.call('tk_entryBackword', self._w)
978 def tk_entrySeeCaret(self):
979 self.tk.call('tk_entrySeeCaret', self._w)
980 def delete(self, first, last=None):
981 self.tk.call(self._w, 'delete', first, last)
982 def get(self):
983 return self.tk.call(self._w, 'get')
984 def icursor(self, index):
985 self.tk.call(self._w, 'icursor', index)
986 def index(self, index):
987 return self.tk.getint(self.tk.call(
988 self._w, 'index', index))
989 def insert(self, index, string):
990 self.tk.call(self._w, 'insert', index, string)
991 def scan_mark(self, x):
992 self.tk.call(self._w, 'scan', 'mark', x)
993 def scan_dragto(self, x):
994 self.tk.call(self._w, 'scan', 'dragto', x)
995 def select_adjust(self, index):
996 self.tk.call(self._w, 'select', 'adjust', index)
997 def select_clear(self):
Guido van Rossum761c5ab1995-07-14 15:29:10 +0000998 self.tk.call(self._w, 'select', 'clear', 'end')
Guido van Rossum18468821994-06-20 07:49:28 +0000999 def select_from(self, index):
Guido van Rossum761c5ab1995-07-14 15:29:10 +00001000 self.tk.call(self._w, 'select', 'set', index)
Guido van Rossum1d59df21995-08-11 14:21:06 +00001001 def select_present(self):
1002 return self.tk.getboolean(
1003 self.tk.call(self._w, 'select', 'present'))
1004 def select_range(self, start, end):
1005 self.tk.call(self._w, 'select', 'range', start, end)
Guido van Rossum18468821994-06-20 07:49:28 +00001006 def select_to(self, index):
1007 self.tk.call(self._w, 'select', 'to', index)
Guido van Rossum761c5ab1995-07-14 15:29:10 +00001008 def view(self, index):
1009 self.tk.call(self._w, 'view', index)
Guido van Rossum18468821994-06-20 07:49:28 +00001010
1011class Frame(Widget):
Guido van Rossum35f67fb1995-08-04 03:50:29 +00001012 def __init__(self, master=None, cnf={}, **kw):
1013 cnf = _cnfmerge((cnf, kw))
Guido van Rossum18468821994-06-20 07:49:28 +00001014 extra = ()
1015 if cnf.has_key('class'):
1016 extra = ('-class', cnf['class'])
1017 del cnf['class']
Guido van Rossum35f67fb1995-08-04 03:50:29 +00001018 Widget.__init__(self, master, 'frame', cnf, {}, extra)
Guido van Rossum18468821994-06-20 07:49:28 +00001019 def tk_menuBar(self, *args):
1020 apply(self.tk.call, ('tk_menuBar', self._w) + args)
1021
1022class Label(Widget):
Guido van Rossum35f67fb1995-08-04 03:50:29 +00001023 def __init__(self, master=None, cnf={}, **kw):
1024 Widget.__init__(self, master, 'label', cnf, kw)
Guido van Rossum761c5ab1995-07-14 15:29:10 +00001025
Guido van Rossum18468821994-06-20 07:49:28 +00001026class Listbox(Widget):
Guido van Rossum35f67fb1995-08-04 03:50:29 +00001027 def __init__(self, master=None, cnf={}, **kw):
1028 Widget.__init__(self, master, 'listbox', cnf, kw)
Guido van Rossum18468821994-06-20 07:49:28 +00001029 def tk_listboxSingleSelect(self):
Guido van Rossum761c5ab1995-07-14 15:29:10 +00001030 if TkVersion >= 4.0:
1031 self['selectmode'] = 'single'
1032 else:
1033 self.tk.call('tk_listboxSingleSelect', self._w)
Guido van Rossum46f92d21995-10-11 17:41:00 +00001034 def activate(self, index):
1035 self.tk.call(self._w, 'activate', index)
Guido van Rossum18468821994-06-20 07:49:28 +00001036 def curselection(self):
1037 return self.tk.splitlist(self.tk.call(
1038 self._w, 'curselection'))
1039 def delete(self, first, last=None):
1040 self.tk.call(self._w, 'delete', first, last)
1041 def get(self, index):
1042 return self.tk.call(self._w, 'get', index)
1043 def insert(self, index, *elements):
1044 apply(self.tk.call,
1045 (self._w, 'insert', index) + elements)
1046 def nearest(self, y):
1047 return self.tk.getint(self.tk.call(
1048 self._w, 'nearest', y))
1049 def scan_mark(self, x, y):
1050 self.tk.call(self._w, 'scan', 'mark', x, y)
1051 def scan_dragto(self, x, y):
1052 self.tk.call(self._w, 'scan', 'dragto', x, y)
1053 def select_adjust(self, index):
1054 self.tk.call(self._w, 'select', 'adjust', index)
Guido van Rossum761c5ab1995-07-14 15:29:10 +00001055 if TkVersion >= 4.0:
1056 def select_anchor(self, index):
1057 self.tk.call(self._w, 'selection', 'anchor', index)
1058 def select_clear(self, first, last=None):
1059 self.tk.call(self._w,
1060 'selection', 'clear', first, last)
1061 def select_includes(self, index):
1062 return self.tk.getboolean(self.tk.call(
1063 self._w, 'selection', 'includes', index))
1064 def select_set(self, first, last=None):
1065 self.tk.call(self._w, 'selection', 'set', first, last)
1066 else:
1067 def select_clear(self):
1068 self.tk.call(self._w, 'select', 'clear')
1069 def select_from(self, index):
1070 self.tk.call(self._w, 'select', 'from', index)
1071 def select_to(self, index):
1072 self.tk.call(self._w, 'select', 'to', index)
Guido van Rossum18468821994-06-20 07:49:28 +00001073 def size(self):
1074 return self.tk.getint(self.tk.call(self._w, 'size'))
Guido van Rossum761c5ab1995-07-14 15:29:10 +00001075 def xview(self, *what):
1076 apply(self.tk.call, (self._w, 'xview')+what)
1077 def yview(self, *what):
1078 apply(self.tk.call, (self._w, 'yview')+what)
Guido van Rossum18468821994-06-20 07:49:28 +00001079
1080class Menu(Widget):
Guido van Rossum35f67fb1995-08-04 03:50:29 +00001081 def __init__(self, master=None, cnf={}, **kw):
1082 Widget.__init__(self, master, 'menu', cnf, kw)
Guido van Rossum18468821994-06-20 07:49:28 +00001083 def tk_bindForTraversal(self):
1084 self.tk.call('tk_bindForTraversal', self._w)
1085 def tk_mbPost(self):
1086 self.tk.call('tk_mbPost', self._w)
1087 def tk_mbUnpost(self):
1088 self.tk.call('tk_mbUnpost')
1089 def tk_traverseToMenu(self, char):
1090 self.tk.call('tk_traverseToMenu', self._w, char)
1091 def tk_traverseWithinMenu(self, char):
1092 self.tk.call('tk_traverseWithinMenu', self._w, char)
1093 def tk_getMenuButtons(self):
1094 return self.tk.call('tk_getMenuButtons', self._w)
1095 def tk_nextMenu(self, count):
1096 self.tk.call('tk_nextMenu', count)
1097 def tk_nextMenuEntry(self, count):
1098 self.tk.call('tk_nextMenuEntry', count)
1099 def tk_invokeMenu(self):
1100 self.tk.call('tk_invokeMenu', self._w)
1101 def tk_firstMenu(self):
1102 self.tk.call('tk_firstMenu', self._w)
1103 def tk_mbButtonDown(self):
1104 self.tk.call('tk_mbButtonDown', self._w)
1105 def activate(self, index):
1106 self.tk.call(self._w, 'activate', index)
Guido van Rossum35f67fb1995-08-04 03:50:29 +00001107 def add(self, itemType, cnf={}, **kw):
Guido van Rossum18468821994-06-20 07:49:28 +00001108 apply(self.tk.call, (self._w, 'add', itemType)
Guido van Rossum35f67fb1995-08-04 03:50:29 +00001109 + self._options(cnf, kw))
Guido van Rossuma1db48b1995-10-09 22:37:28 +00001110 def add_cascade(self, cnf={}, **kw):
1111 self.add('cascade', cnf or kw)
1112 def add_checkbutton(self, cnf={}, **kw):
1113 self.add('checkbutton', cnf or kw)
1114 def add_command(self, cnf={}, **kw):
1115 self.add('command', cnf or kw)
1116 def add_radiobutton(self, cnf={}, **kw):
1117 self.add('radiobutton', cnf or kw)
1118 def add_separator(self, cnf={}, **kw):
1119 self.add('separator', cnf or kw)
Guido van Rossum18468821994-06-20 07:49:28 +00001120 def delete(self, index1, index2=None):
1121 self.tk.call(self._w, 'delete', index1, index2)
Guido van Rossum35f67fb1995-08-04 03:50:29 +00001122 def entryconfig(self, index, cnf={}, **kw):
Guido van Rossum18468821994-06-20 07:49:28 +00001123 apply(self.tk.call, (self._w, 'entryconfigure', index)
Guido van Rossum35f67fb1995-08-04 03:50:29 +00001124 + self._options(cnf, kw))
Guido van Rossum18468821994-06-20 07:49:28 +00001125 def index(self, index):
Guido van Rossum535cf0c1994-06-27 07:55:59 +00001126 i = self.tk.call(self._w, 'index', index)
1127 if i == 'none': return None
1128 return self.tk.getint(i)
Guido van Rossum18468821994-06-20 07:49:28 +00001129 def invoke(self, index):
1130 return self.tk.call(self._w, 'invoke', index)
1131 def post(self, x, y):
1132 self.tk.call(self._w, 'post', x, y)
1133 def unpost(self):
1134 self.tk.call(self._w, 'unpost')
1135 def yposition(self, index):
1136 return self.tk.getint(self.tk.call(
1137 self._w, 'yposition', index))
1138
1139class Menubutton(Widget):
Guido van Rossum35f67fb1995-08-04 03:50:29 +00001140 def __init__(self, master=None, cnf={}, **kw):
1141 Widget.__init__(self, master, 'menubutton', cnf, kw)
Guido van Rossum18468821994-06-20 07:49:28 +00001142
1143class Message(Widget):
Guido van Rossum35f67fb1995-08-04 03:50:29 +00001144 def __init__(self, master=None, cnf={}, **kw):
1145 Widget.__init__(self, master, 'message', cnf, kw)
Guido van Rossum18468821994-06-20 07:49:28 +00001146
1147class Radiobutton(Widget):
Guido van Rossum35f67fb1995-08-04 03:50:29 +00001148 def __init__(self, master=None, cnf={}, **kw):
1149 Widget.__init__(self, master, 'radiobutton', cnf, kw)
Guido van Rossum18468821994-06-20 07:49:28 +00001150 def deselect(self):
1151 self.tk.call(self._w, 'deselect')
1152 def flash(self):
1153 self.tk.call(self._w, 'flash')
1154 def invoke(self):
1155 self.tk.call(self._w, 'invoke')
1156 def select(self):
1157 self.tk.call(self._w, 'select')
1158
1159class Scale(Widget):
Guido van Rossum35f67fb1995-08-04 03:50:29 +00001160 def __init__(self, master=None, cnf={}, **kw):
1161 Widget.__init__(self, master, 'scale', cnf, kw)
Guido van Rossum18468821994-06-20 07:49:28 +00001162 def get(self):
1163 return self.tk.getint(self.tk.call(self._w, 'get'))
1164 def set(self, value):
1165 self.tk.call(self._w, 'set', value)
1166
1167class Scrollbar(Widget):
Guido van Rossum35f67fb1995-08-04 03:50:29 +00001168 def __init__(self, master=None, cnf={}, **kw):
1169 Widget.__init__(self, master, 'scrollbar', cnf, kw)
Guido van Rossum18468821994-06-20 07:49:28 +00001170 def get(self):
Guido van Rossumaec5dc91994-06-27 07:55:12 +00001171 return self._getints(self.tk.call(self._w, 'get'))
Guido van Rossum761c5ab1995-07-14 15:29:10 +00001172 def set(self, *args):
1173 apply(self.tk.call, (self._w, 'set')+args)
Guido van Rossum18468821994-06-20 07:49:28 +00001174
1175class Text(Widget):
Guido van Rossum35f67fb1995-08-04 03:50:29 +00001176 def __init__(self, master=None, cnf={}, **kw):
1177 Widget.__init__(self, master, 'text', cnf, kw)
Guido van Rossum761c5ab1995-07-14 15:29:10 +00001178 self.bind('<Delete>', self.bspace)
1179 def bspace(self, *args):
1180 self.delete('insert')
Guido van Rossum18468821994-06-20 07:49:28 +00001181 def tk_textSelectTo(self, index):
1182 self.tk.call('tk_textSelectTo', self._w, index)
1183 def tk_textBackspace(self):
1184 self.tk.call('tk_textBackspace', self._w)
1185 def tk_textIndexCloser(self, a, b, c):
1186 self.tk.call('tk_textIndexCloser', self._w, a, b, c)
1187 def tk_textResetAnchor(self, index):
1188 self.tk.call('tk_textResetAnchor', self._w, index)
1189 def compare(self, index1, op, index2):
1190 return self.tk.getboolean(self.tk.call(
1191 self._w, 'compare', index1, op, index2))
1192 def debug(self, boolean=None):
1193 return self.tk.getboolean(self.tk.call(
1194 self._w, 'debug', boolean))
1195 def delete(self, index1, index2=None):
1196 self.tk.call(self._w, 'delete', index1, index2)
1197 def get(self, index1, index2=None):
1198 return self.tk.call(self._w, 'get', index1, index2)
1199 def index(self, index):
1200 return self.tk.call(self._w, 'index', index)
Guido van Rossum35f67fb1995-08-04 03:50:29 +00001201 def insert(self, index, chars, *args):
1202 apply(self.tk.call, (self._w, 'insert', index, chars)+args)
Guido van Rossum18468821994-06-20 07:49:28 +00001203 def mark_names(self):
1204 return self.tk.splitlist(self.tk.call(
1205 self._w, 'mark', 'names'))
1206 def mark_set(self, markName, index):
1207 self.tk.call(self._w, 'mark', 'set', markName, index)
1208 def mark_unset(self, markNames):
1209 apply(self.tk.call, (self._w, 'mark', 'unset') + markNames)
1210 def scan_mark(self, y):
1211 self.tk.call(self._w, 'scan', 'mark', y)
1212 def scan_dragto(self, y):
1213 self.tk.call(self._w, 'scan', 'dragto', y)
Guido van Rossum96ebbd31995-09-30 17:05:26 +00001214 def search(self, pattern, index, stopindex=None,
1215 forwards=None, backwards=None, exact=None,
1216 regexp=None, nocase=None, count=None):
1217 args = [self._w, 'search']
1218 if forwards: args.append('-forwards')
1219 if backwards: args.append('-backwards')
1220 if exact: args.append('-exact')
1221 if regexp: args.append('-regexp')
1222 if nocase: args.append('-nocase')
1223 if count: args.append('-count'); args.append(count)
1224 if pattern[0] == '-': args.append('--')
1225 args.append(pattern)
1226 args.append(index)
1227 if stopindex: args.append(stopindex)
1228 return apply(self.tk.call, tuple(args))
Guido van Rossum18468821994-06-20 07:49:28 +00001229 def tag_add(self, tagName, index1, index2=None):
1230 self.tk.call(
1231 self._w, 'tag', 'add', tagName, index1, index2)
Guido van Rossumef8f8811994-08-08 12:47:33 +00001232 def tag_unbind(self, tagName, sequence):
1233 self.tk.call(self._w, 'tag', 'bind', tagName, sequence, '')
Guido van Rossum18468821994-06-20 07:49:28 +00001234 def tag_bind(self, tagName, sequence, func, add=''):
Guido van Rossum18468821994-06-20 07:49:28 +00001235 if add: add='+'
Guido van Rossum45853db1994-06-20 12:19:19 +00001236 name = self._register(func, self._substitute)
Guido van Rossum18468821994-06-20 07:49:28 +00001237 self.tk.call(self._w, 'tag', 'bind',
1238 tagName, sequence,
Guido van Rossumaec5dc91994-06-27 07:55:12 +00001239 (add + name,) + self._subst_format)
Guido van Rossum35f67fb1995-08-04 03:50:29 +00001240 def tag_config(self, tagName, cnf={}, **kw):
Guido van Rossum18468821994-06-20 07:49:28 +00001241 apply(self.tk.call,
Guido van Rossum35f67fb1995-08-04 03:50:29 +00001242 (self._w, 'tag', 'configure', tagName)
1243 + self._options(cnf, kw))
Guido van Rossum2dcf5291994-07-06 09:23:20 +00001244 def tag_delete(self, *tagNames):
Guido van Rossum2a390311994-07-06 10:20:11 +00001245 apply(self.tk.call, (self._w, 'tag', 'delete') + tagNames)
Guido van Rossum18468821994-06-20 07:49:28 +00001246 def tag_lower(self, tagName, belowThis=None):
Guido van Rossum97aeca11994-07-07 13:12:12 +00001247 self.tk.call(self._w, 'tag', 'lower', tagName, belowThis)
Guido van Rossum18468821994-06-20 07:49:28 +00001248 def tag_names(self, index=None):
1249 return self.tk.splitlist(
1250 self.tk.call(self._w, 'tag', 'names', index))
1251 def tag_nextrange(self, tagName, index1, index2=None):
1252 return self.tk.splitlist(self.tk.call(
Guido van Rossum903abee1995-03-20 15:09:13 +00001253 self._w, 'tag', 'nextrange', tagName, index1, index2))
Guido van Rossum18468821994-06-20 07:49:28 +00001254 def tag_raise(self, tagName, aboveThis=None):
1255 self.tk.call(
1256 self._w, 'tag', 'raise', tagName, aboveThis)
1257 def tag_ranges(self, tagName):
1258 return self.tk.splitlist(self.tk.call(
1259 self._w, 'tag', 'ranges', tagName))
1260 def tag_remove(self, tagName, index1, index2=None):
1261 self.tk.call(
Guido van Rossum51135691994-07-06 21:16:58 +00001262 self._w, 'tag', 'remove', tagName, index1, index2)
Guido van Rossum35f67fb1995-08-04 03:50:29 +00001263 def window_cget(self, index, option):
1264 return self.tk.call(self._w, 'window', 'cget', index, option)
1265 def window_config(self, index, cnf={}, **kw):
1266 apply(self.tk.call,
1267 (self._w, 'window', 'configure', index)
1268 + self._options(cnf, kw))
1269 def window_create(self, index, cnf={}, **kw):
1270 apply(self.tk.call,
1271 (self._w, 'window', 'create', index)
1272 + self._options(cnf, kw))
1273 def window_names(self):
1274 return self.tk.splitlist(
1275 self.tk.call(self._w, 'window', 'names'))
Guido van Rossum761c5ab1995-07-14 15:29:10 +00001276 def yview(self, *what):
1277 apply(self.tk.call, (self._w, 'yview')+what)
1278 def yview_pickplace(self, *what):
1279 apply(self.tk.call, (self._w, 'yview', '-pickplace')+what)
Guido van Rossum18468821994-06-20 07:49:28 +00001280
Guido van Rossumbf4d8f91995-09-01 20:35:37 +00001281class OptionMenu(Widget):
1282 def __init__(self, master, variable, value, *values):
1283 self.widgetName = 'tk_optionMenu'
1284 Widget._setup(self, master, {})
1285 self.menuname = apply(
1286 self.tk.call,
1287 (self.widgetName, self._w, variable, value) + values)
1288
Guido van Rossum35f67fb1995-08-04 03:50:29 +00001289class Image:
1290 def __init__(self, imgtype, name=None, cnf={}, **kw):
1291 self.name = None
1292 master = _default_root
1293 if not master: raise RuntimeError, 'Too early to create image'
1294 self.tk = master.tk
1295 if not name: name = `id(self)`
1296 if kw and cnf: cnf = _cnfmerge((cnf, kw))
1297 elif kw: cnf = kw
1298 options = ()
1299 for k, v in cnf.items():
1300 if type(v) in CallableTypes:
1301 v = self._register(v)
1302 options = options + ('-'+k, v)
1303 apply(self.tk.call,
1304 ('image', 'create', imgtype, name,) + options)
1305 self.name = name
1306 def __str__(self): return self.name
1307 def __del__(self):
1308 if self.name:
1309 self.tk.call('image', 'delete', self.name)
Guido van Rossum71b1a901995-09-18 21:54:35 +00001310 def __setitem__(self, key, value):
1311 self.tk.call(self.name, 'configure', '-'+key, value)
1312 def __getitem__(self, key):
1313 return self.tk.call(self.name, 'configure', '-'+key)
Guido van Rossum35f67fb1995-08-04 03:50:29 +00001314 def height(self):
1315 return self.tk.getint(
1316 self.tk.call('image', 'height', self.name))
1317 def type(self):
1318 return self.tk.call('image', 'type', self.name)
1319 def width(self):
1320 return self.tk.getint(
1321 self.tk.call('image', 'width', self.name))
1322
1323class PhotoImage(Image):
1324 def __init__(self, name=None, cnf={}, **kw):
1325 apply(Image.__init__, (self, 'photo', name, cnf), kw)
Guido van Rossum96ebbd31995-09-30 17:05:26 +00001326 def blank(self):
1327 self.tk.call(self.name, 'blank')
1328 def cget(self):
1329 return self.tk.call(self.name, 'cget')
1330 # XXX config
1331 # XXX copy
1332 def get(self, x, y):
1333 return self.tk.call(self.name, 'get', x, y)
1334 def put(self, data, to=None):
1335 args = (self.name, 'put', data)
1336 if to:
1337 args = args + to
1338 apply(self.tk.call, args)
1339 # XXX read
1340 # XXX write
Guido van Rossum35f67fb1995-08-04 03:50:29 +00001341
1342class BitmapImage(Image):
1343 def __init__(self, name=None, cnf={}, **kw):
1344 apply(Image.__init__, (self, 'bitmap', name, cnf), kw)
1345
1346def image_names(): return _default_root.tk.call('image', 'names')
1347def image_types(): return _default_root.tk.call('image', 'types')
1348
Guido van Rossumaec5dc91994-06-27 07:55:12 +00001349######################################################################
1350# Extensions:
1351
1352class Studbutton(Button):
Guido van Rossum35f67fb1995-08-04 03:50:29 +00001353 def __init__(self, master=None, cnf={}, **kw):
1354 Widget.__init__(self, master, 'studbutton', cnf, kw)
Guido van Rossum761c5ab1995-07-14 15:29:10 +00001355 self.bind('<Any-Enter>', self.tkButtonEnter)
1356 self.bind('<Any-Leave>', self.tkButtonLeave)
1357 self.bind('<1>', self.tkButtonDown)
1358 self.bind('<ButtonRelease-1>', self.tkButtonUp)
Guido van Rossumaec5dc91994-06-27 07:55:12 +00001359
1360class Tributton(Button):
Guido van Rossum35f67fb1995-08-04 03:50:29 +00001361 def __init__(self, master=None, cnf={}, **kw):
1362 Widget.__init__(self, master, 'tributton', cnf, kw)
Guido van Rossum761c5ab1995-07-14 15:29:10 +00001363 self.bind('<Any-Enter>', self.tkButtonEnter)
1364 self.bind('<Any-Leave>', self.tkButtonLeave)
1365 self.bind('<1>', self.tkButtonDown)
1366 self.bind('<ButtonRelease-1>', self.tkButtonUp)
1367 self['fg'] = self['bg']
1368 self['activebackground'] = self['bg']