blob: 5dd0c99b186f0cc9101731f9e75573ccd1c5fb33 [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 Rossum37dcab11996-05-16 16:00:19 +00003__version__ = "$Revision$"
4
5try:
6 # See if modern _tkinter is present
7 import _tkinter
8 tkinter = _tkinter # b/w compat
9except ImportError:
10 # No modern _tkinter -- try oldfashioned tkinter
11 import tkinter
12 if hasattr(tkinter, "__path__"):
13 import sys, os
14 # Append standard platform specific directory
15 p = tkinter.__path__
16 for dir in sys.path:
17 if (dir not in p and
18 os.path.basename(dir) == sys.platform):
19 p.append(dir)
20 del sys, os, p, dir
21 from tkinter import tkinter
22TclError = tkinter.TclError
Guido van Rossum7e9394a1995-03-17 16:21:33 +000023from types import *
Guido van Rossuma5773dd1995-09-07 19:22:00 +000024from Tkconstants import *
Guido van Rossum37dcab11996-05-16 16:00:19 +000025import string; _string = string; del string
Guido van Rossum18468821994-06-20 07:49:28 +000026
Guido van Rossum36269991996-05-16 17:11:27 +000027TkVersion = _string.atof(tkinter.TK_VERSION)
28TclVersion = _string.atof(tkinter.TCL_VERSION)
Guido van Rossum18468821994-06-20 07:49:28 +000029
Guido van Rossum36269991996-05-16 17:11:27 +000030######################################################################
31# Since the values of file event masks changed from Tk 4.0 to Tk 4.1,
32# they are defined here (and not in Tkconstants):
33######################################################################
34if TkVersion >= 4.1:
35 READABLE = 2
36 WRITABLE = 4
37 EXCEPTION = 8
38else:
39 READABLE = 1
40 WRITABLE = 2
41 EXCEPTION = 4
42
43
Guido van Rossum2dcf5291994-07-06 09:23:20 +000044def _flatten(tuple):
45 res = ()
46 for item in tuple:
47 if type(item) in (TupleType, ListType):
48 res = res + _flatten(item)
Guido van Rossum35f67fb1995-08-04 03:50:29 +000049 elif item is not None:
Guido van Rossum2dcf5291994-07-06 09:23:20 +000050 res = res + (item,)
51 return res
52
53def _cnfmerge(cnfs):
Guido van Rossum761c5ab1995-07-14 15:29:10 +000054 if type(cnfs) is DictionaryType:
Guido van Rossum761c5ab1995-07-14 15:29:10 +000055 return cnfs
56 elif type(cnfs) in (NoneType, StringType):
57
Guido van Rossum2dcf5291994-07-06 09:23:20 +000058 return cnfs
59 else:
60 cnf = {}
61 for c in _flatten(cnfs):
62 for k, v in c.items():
63 cnf[k] = v
64 return cnf
65
66class Event:
67 pass
68
Guido van Rossumaec5dc91994-06-27 07:55:12 +000069_default_root = None
70
Guido van Rossum45853db1994-06-20 12:19:19 +000071def _tkerror(err):
Guido van Rossum18468821994-06-20 07:49:28 +000072 pass
73
Guido van Rossum97aeca11994-07-07 13:12:12 +000074def _exit(code='0'):
Guido van Rossum37dcab11996-05-16 16:00:19 +000075 raise SystemExit, code
Guido van Rossum97aeca11994-07-07 13:12:12 +000076
Guido van Rossumaec5dc91994-06-27 07:55:12 +000077_varnum = 0
78class Variable:
Guido van Rossume1a7a3b1996-09-05 16:45:49 +000079 _default = ""
Guido van Rossumaec5dc91994-06-27 07:55:12 +000080 def __init__(self, master=None):
81 global _default_root
82 global _varnum
83 if master:
84 self._tk = master.tk
85 else:
86 self._tk = _default_root.tk
87 self._name = 'PY_VAR' + `_varnum`
88 _varnum = _varnum + 1
Guido van Rossume1a7a3b1996-09-05 16:45:49 +000089 self.set(self._default)
Guido van Rossumaec5dc91994-06-27 07:55:12 +000090 def __del__(self):
Guido van Rossum37dcab11996-05-16 16:00:19 +000091 self._tk.globalunsetvar(self._name)
Guido van Rossumaec5dc91994-06-27 07:55:12 +000092 def __str__(self):
93 return self._name
Guido van Rossumaec5dc91994-06-27 07:55:12 +000094 def set(self, value):
Guido van Rossum37dcab11996-05-16 16:00:19 +000095 return self._tk.globalsetvar(self._name, value)
Guido van Rossumaec5dc91994-06-27 07:55:12 +000096
97class StringVar(Variable):
Guido van Rossume1a7a3b1996-09-05 16:45:49 +000098 _default = ""
Guido van Rossumaec5dc91994-06-27 07:55:12 +000099 def __init__(self, master=None):
100 Variable.__init__(self, master)
101 def get(self):
Guido van Rossum37dcab11996-05-16 16:00:19 +0000102 return self._tk.globalgetvar(self._name)
Guido van Rossumaec5dc91994-06-27 07:55:12 +0000103
104class IntVar(Variable):
Guido van Rossume1a7a3b1996-09-05 16:45:49 +0000105 _default = "0"
Guido van Rossumaec5dc91994-06-27 07:55:12 +0000106 def __init__(self, master=None):
107 Variable.__init__(self, master)
108 def get(self):
Guido van Rossum37dcab11996-05-16 16:00:19 +0000109 return self._tk.getint(self._tk.globalgetvar(self._name))
Guido van Rossumaec5dc91994-06-27 07:55:12 +0000110
111class DoubleVar(Variable):
Guido van Rossume1a7a3b1996-09-05 16:45:49 +0000112 _default = "0.0"
Guido van Rossumaec5dc91994-06-27 07:55:12 +0000113 def __init__(self, master=None):
114 Variable.__init__(self, master)
115 def get(self):
Guido van Rossum37dcab11996-05-16 16:00:19 +0000116 return self._tk.getdouble(self._tk.globalgetvar(self._name))
Guido van Rossumaec5dc91994-06-27 07:55:12 +0000117
118class BooleanVar(Variable):
Guido van Rossume1a7a3b1996-09-05 16:45:49 +0000119 _default = "false"
Guido van Rossumaec5dc91994-06-27 07:55:12 +0000120 def __init__(self, master=None):
121 Variable.__init__(self, master)
122 def get(self):
Guido van Rossum37dcab11996-05-16 16:00:19 +0000123 return self._tk.getboolean(self._tk.globalgetvar(self._name))
Guido van Rossumaec5dc91994-06-27 07:55:12 +0000124
Guido van Rossum35f67fb1995-08-04 03:50:29 +0000125def mainloop(n=0):
126 _default_root.tk.mainloop(n)
Guido van Rossum2dcf5291994-07-06 09:23:20 +0000127
128def getint(s):
129 return _default_root.tk.getint(s)
130
131def getdouble(s):
132 return _default_root.tk.getdouble(s)
133
134def getboolean(s):
135 return _default_root.tk.getboolean(s)
136
Guido van Rossum18468821994-06-20 07:49:28 +0000137class Misc:
138 def tk_strictMotif(self, boolean=None):
Guido van Rossum2dcf5291994-07-06 09:23:20 +0000139 return self.tk.getboolean(self.tk.call(
Guido van Rossum18468821994-06-20 07:49:28 +0000140 'set', 'tk_strictMotif', boolean))
Fred Drake3c602d71996-09-27 14:06:54 +0000141 def tk_bisque(self):
142 self.tk.call('tk_bisque')
143 def tk_setPalette(self, *args, **kw):
Fred Drake3faf9b41996-10-04 19:23:04 +0000144 apply(self.tk.call, ('tk_setPalette',)
145 + _flatten(args) + _flatten(kw.items()))
Guido van Rossumaec5dc91994-06-27 07:55:12 +0000146 def tk_menuBar(self, *args):
Guido van Rossum688bbfc1996-09-10 12:39:26 +0000147 pass # obsolete since Tk 4.0
Guido van Rossum2dcf5291994-07-06 09:23:20 +0000148 def wait_variable(self, name='PY_VAR'):
Guido van Rossum18468821994-06-20 07:49:28 +0000149 self.tk.call('tkwait', 'variable', name)
Guido van Rossum2dcf5291994-07-06 09:23:20 +0000150 waitvar = wait_variable # XXX b/w compat
Guido van Rossum9beb9321994-06-27 23:15:31 +0000151 def wait_window(self, window=None):
152 if window == None:
153 window = self
154 self.tk.call('tkwait', 'window', window._w)
155 def wait_visibility(self, window=None):
156 if window == None:
157 window = self
158 self.tk.call('tkwait', 'visibility', window._w)
Guido van Rossumaec5dc91994-06-27 07:55:12 +0000159 def setvar(self, name='PY_VAR', value='1'):
Guido van Rossum18468821994-06-20 07:49:28 +0000160 self.tk.setvar(name, value)
Guido van Rossumaec5dc91994-06-27 07:55:12 +0000161 def getvar(self, name='PY_VAR'):
Guido van Rossum5e8d3721994-06-20 08:12:01 +0000162 return self.tk.getvar(name)
163 def getint(self, s):
164 return self.tk.getint(s)
Guido van Rossum1e9e4001994-06-20 09:09:51 +0000165 def getdouble(self, s):
166 return self.tk.getdouble(s)
167 def getboolean(self, s):
168 return self.tk.getboolean(s)
Guido van Rossum45853db1994-06-20 12:19:19 +0000169 def focus_set(self):
Guido van Rossum18468821994-06-20 07:49:28 +0000170 self.tk.call('focus', self._w)
Guido van Rossum45853db1994-06-20 12:19:19 +0000171 focus = focus_set # XXX b/w compat?
Fred Drake3c602d71996-09-27 14:06:54 +0000172 def focus_force(self):
173 self.tk.call('focus', '-force', self._w)
Guido van Rossum45853db1994-06-20 12:19:19 +0000174 def focus_get(self):
175 name = self.tk.call('focus')
Guido van Rossum5468a7b1996-08-08 18:31:42 +0000176 if name == 'none' or not name: return None
Guido van Rossum45853db1994-06-20 12:19:19 +0000177 return self._nametowidget(name)
Fred Drake3c602d71996-09-27 14:06:54 +0000178 def focus_displayof(self):
179 name = self.tk.call('focus', '-displayof', self._w)
180 if name == 'none' or not name: return None
181 return self._nametowidget(name)
182 def focus_lastfor(self):
183 name = self.tk.call('focus', '-lastfor', self._w)
184 if name == 'none' or not name: return None
185 return self._nametowidget(name)
186 def tk_focusFollowsMouse(self):
187 self.tk.call('tk_focusFollowsMouse')
Guido van Rossum37dcab11996-05-16 16:00:19 +0000188 def tk_focusNext(self):
189 name = self.tk.call('tk_focusNext', self._w)
190 if not name: return None
191 return self._nametowidget(name)
192 def tk_focusPrev(self):
193 name = self.tk.call('tk_focusPrev', self._w)
194 if not name: return None
195 return self._nametowidget(name)
Guido van Rossum18468821994-06-20 07:49:28 +0000196 def after(self, ms, func=None, *args):
197 if not func:
Guido van Rossum96ebbd31995-09-30 17:05:26 +0000198 # I'd rather use time.sleep(ms*0.001)
Guido van Rossum18468821994-06-20 07:49:28 +0000199 self.tk.call('after', ms)
200 else:
Guido van Rossum08a40381994-06-21 11:44:21 +0000201 # XXX Disgusting hack to clean up after calling func
202 tmp = []
203 def callit(func=func, args=args, tk=self.tk, tmp=tmp):
204 try:
205 apply(func, args)
206 finally:
207 tk.deletecommand(tmp[0])
208 name = self._register(callit)
209 tmp.append(name)
Guido van Rossum96ebbd31995-09-30 17:05:26 +0000210 return self.tk.call('after', ms, name)
211 def after_idle(self, func, *args):
212 return apply(self.after, ('idle', func) + args)
213 def after_cancel(self, id):
214 self.tk.call('after', 'cancel', id)
Fred Drake3c602d71996-09-27 14:06:54 +0000215 def bell(self, displayof=0):
216 apply(self.tk.call, ('bell',) + self._displayof(displayof))
217 # Clipboard handling:
218 def clipboard_clear(self, **kw):
219 if not kw.has_key('displayof'): kw['displayof'] = self._w
220 apply(self.tk.call,
221 ('clipboard', 'clear') + self._options(kw))
222 def clipboard_append(self, string, **kw):
223 if not kw.has_key('displayof'): kw['displayof'] = self._w
224 apply(self.tk.call,
225 ('clipboard', 'append') + self._options(kw)
226 + ('--', string))
Guido van Rossum45853db1994-06-20 12:19:19 +0000227 # XXX grab current w/o window argument
228 def grab_current(self):
229 name = self.tk.call('grab', 'current', self._w)
230 if not name: return None
231 return self._nametowidget(name)
Guido van Rossum18468821994-06-20 07:49:28 +0000232 def grab_release(self):
233 self.tk.call('grab', 'release', self._w)
234 def grab_set(self):
235 self.tk.call('grab', 'set', self._w)
236 def grab_set_global(self):
237 self.tk.call('grab', 'set', '-global', self._w)
238 def grab_status(self):
Guido van Rossum45853db1994-06-20 12:19:19 +0000239 status = self.tk.call('grab', 'status', self._w)
240 if status == 'none': status = None
241 return status
Guido van Rossum18468821994-06-20 07:49:28 +0000242 def lower(self, belowThis=None):
243 self.tk.call('lower', self._w, belowThis)
Guido van Rossum780044f1994-10-20 22:02:27 +0000244 def option_add(self, pattern, value, priority = None):
Guido van Rossum96ebbd31995-09-30 17:05:26 +0000245 self.tk.call('option', 'add', pattern, value, priority)
Guido van Rossum780044f1994-10-20 22:02:27 +0000246 def option_clear(self):
247 self.tk.call('option', 'clear')
248 def option_get(self, name, className):
249 return self.tk.call('option', 'get', self._w, name, className)
250 def option_readfile(self, fileName, priority = None):
251 self.tk.call('option', 'readfile', fileName, priority)
Fred Drake3c602d71996-09-27 14:06:54 +0000252 def selection_clear(self, **kw):
253 if not kw.has_key('displayof'): kw['displayof'] = self._w
254 apply(self.tk.call, ('selection', 'clear') + self._options(kw))
255 def selection_get(self, **kw):
256 if not kw.has_key('displayof'): kw['displayof'] = self._w
257 return apply(self.tk.call,
258 ('selection', 'get') + self._options(kw))
259 def selection_handle(self, command, **kw):
260 name = self._register(command)
261 apply(self.tk.call,
262 ('selection', 'handle') + self._options(kw)
263 + (self._w, name))
264 def selection_own(self, **kw):
265 "Become owner of X selection."
266 apply(self.tk.call,
267 ('selection', 'own') + self._options(kw) + (self._w,))
268 def selection_own_get(self, **kw):
269 "Find owner of X selection."
270 if not kw.has_key('displayof'): kw['displayof'] = self._w
271 return self._nametowidget(
272 apply(self.tk.call,
273 ('selection', 'own') + self._options(kw)))
Guido van Rossumaec5dc91994-06-27 07:55:12 +0000274 def send(self, interp, cmd, *args):
Guido van Rossum18468821994-06-20 07:49:28 +0000275 return apply(self.tk.call, ('send', interp, cmd) + args)
Guido van Rossum5e8d3721994-06-20 08:12:01 +0000276 def lower(self, belowThis=None):
Guido van Rossum6e8ec591996-09-11 14:25:41 +0000277 self.tk.call('lower', self._w, belowThis)
Guido van Rossum5e8d3721994-06-20 08:12:01 +0000278 def tkraise(self, aboveThis=None):
279 self.tk.call('raise', self._w, aboveThis)
280 lift = tkraise
Guido van Rossum18468821994-06-20 07:49:28 +0000281 def colormodel(self, value=None):
282 return self.tk.call('tk', 'colormodel', self._w, value)
Fred Drake3c602d71996-09-27 14:06:54 +0000283 def winfo_atom(self, name, displayof=0):
284 args = ('winfo', 'atom') + self._displayof(displayof) + (name,)
285 return self.tk.getint(apply(self.tk.call, args))
286 def winfo_atomname(self, id, displayof=0):
287 args = ('winfo', 'atomname') \
288 + self._displayof(displayof) + (id,)
289 return apply(self.tk.call, args)
Guido van Rossum18468821994-06-20 07:49:28 +0000290 def winfo_cells(self):
291 return self.tk.getint(
292 self.tk.call('winfo', 'cells', self._w))
Guido van Rossum45853db1994-06-20 12:19:19 +0000293 def winfo_children(self):
294 return map(self._nametowidget,
295 self.tk.splitlist(self.tk.call(
296 'winfo', 'children', self._w)))
Guido van Rossum18468821994-06-20 07:49:28 +0000297 def winfo_class(self):
298 return self.tk.call('winfo', 'class', self._w)
Fred Drake3c602d71996-09-27 14:06:54 +0000299 def winfo_colormapfull(self):
300 return self.tk.getboolean(
301 self.tk.call('winfo', 'colormapfull'))
302 def winfo_containing(self, rootX, rootY, displayof=0):
303 args = ('winfo', 'containing') \
304 + self._displayof(displayof) + (rootX, rootY)
305 return self._nametowidget(apply(self.tk.call, args))
Guido van Rossum18468821994-06-20 07:49:28 +0000306 def winfo_depth(self):
307 return self.tk.getint(self.tk.call('winfo', 'depth', self._w))
308 def winfo_exists(self):
309 return self.tk.getint(
310 self.tk.call('winfo', 'exists', self._w))
311 def winfo_fpixels(self, number):
312 return self.tk.getdouble(self.tk.call(
313 'winfo', 'fpixels', self._w, number))
314 def winfo_geometry(self):
315 return self.tk.call('winfo', 'geometry', self._w)
316 def winfo_height(self):
317 return self.tk.getint(
318 self.tk.call('winfo', 'height', self._w))
319 def winfo_id(self):
320 return self.tk.getint(
321 self.tk.call('winfo', 'id', self._w))
Fred Drake3c602d71996-09-27 14:06:54 +0000322 def winfo_interps(self, displayof=0):
323 args = ('winfo', 'interps') + self._displayof(displayof)
324 return self.tk.splitlist(apply(self.tk.call, args))
Guido van Rossum18468821994-06-20 07:49:28 +0000325 def winfo_ismapped(self):
326 return self.tk.getint(
327 self.tk.call('winfo', 'ismapped', self._w))
328 def winfo_name(self):
329 return self.tk.call('winfo', 'name', self._w)
330 def winfo_parent(self):
331 return self.tk.call('winfo', 'parent', self._w)
Fred Drake3c602d71996-09-27 14:06:54 +0000332 def winfo_pathname(self, id, displayof=0):
333 args = ('winfo', 'pathname') \
334 + self._displayof(displayof) + (id,)
335 return apply(self.tk.call, args)
Guido van Rossum18468821994-06-20 07:49:28 +0000336 def winfo_pixels(self, number):
337 return self.tk.getint(
338 self.tk.call('winfo', 'pixels', self._w, number))
339 def winfo_reqheight(self):
340 return self.tk.getint(
341 self.tk.call('winfo', 'reqheight', self._w))
342 def winfo_reqwidth(self):
343 return self.tk.getint(
344 self.tk.call('winfo', 'reqwidth', self._w))
345 def winfo_rgb(self, color):
346 return self._getints(
347 self.tk.call('winfo', 'rgb', self._w, color))
348 def winfo_rootx(self):
349 return self.tk.getint(
350 self.tk.call('winfo', 'rootx', self._w))
351 def winfo_rooty(self):
352 return self.tk.getint(
353 self.tk.call('winfo', 'rooty', self._w))
354 def winfo_screen(self):
355 return self.tk.call('winfo', 'screen', self._w)
356 def winfo_screencells(self):
357 return self.tk.getint(
358 self.tk.call('winfo', 'screencells', self._w))
359 def winfo_screendepth(self):
360 return self.tk.getint(
361 self.tk.call('winfo', 'screendepth', self._w))
362 def winfo_screenheight(self):
363 return self.tk.getint(
364 self.tk.call('winfo', 'screenheight', self._w))
365 def winfo_screenmmheight(self):
366 return self.tk.getint(
367 self.tk.call('winfo', 'screenmmheight', self._w))
368 def winfo_screenmmwidth(self):
369 return self.tk.getint(
370 self.tk.call('winfo', 'screenmmwidth', self._w))
371 def winfo_screenvisual(self):
372 return self.tk.call('winfo', 'screenvisual', self._w)
373 def winfo_screenwidth(self):
374 return self.tk.getint(
375 self.tk.call('winfo', 'screenwidth', self._w))
376 def winfo_toplevel(self):
Guido van Rossumaec5dc91994-06-27 07:55:12 +0000377 return self._nametowidget(self.tk.call(
378 'winfo', 'toplevel', self._w))
Guido van Rossum18468821994-06-20 07:49:28 +0000379 def winfo_visual(self):
380 return self.tk.call('winfo', 'visual', self._w)
381 def winfo_vrootheight(self):
382 return self.tk.getint(
383 self.tk.call('winfo', 'vrootheight', self._w))
384 def winfo_vrootwidth(self):
385 return self.tk.getint(
386 self.tk.call('winfo', 'vrootwidth', self._w))
387 def winfo_vrootx(self):
388 return self.tk.getint(
389 self.tk.call('winfo', 'vrootx', self._w))
390 def winfo_vrooty(self):
391 return self.tk.getint(
392 self.tk.call('winfo', 'vrooty', self._w))
393 def winfo_width(self):
394 return self.tk.getint(
395 self.tk.call('winfo', 'width', self._w))
396 def winfo_x(self):
397 return self.tk.getint(
398 self.tk.call('winfo', 'x', self._w))
399 def winfo_y(self):
400 return self.tk.getint(
401 self.tk.call('winfo', 'y', self._w))
402 def update(self):
403 self.tk.call('update')
404 def update_idletasks(self):
405 self.tk.call('update', 'idletasks')
Guido van Rossum37dcab11996-05-16 16:00:19 +0000406 def bindtags(self, tagList=None):
407 if tagList is None:
408 return self.tk.splitlist(
409 self.tk.call('bindtags', self._w))
Guido van Rossum761c5ab1995-07-14 15:29:10 +0000410 else:
Guido van Rossum37dcab11996-05-16 16:00:19 +0000411 self.tk.call('bindtags', self._w, tagList)
412 def _bind(self, what, sequence, func, add):
413 if func:
414 cmd = ("%sset _tkinter_break [%s %s]\n"
415 'if {"$_tkinter_break" == "break"} break\n') \
416 % (add and '+' or '',
417 self._register(func, self._substitute),
418 _string.join(self._subst_format))
419 apply(self.tk.call, what + (sequence, cmd))
420 elif func == '':
421 apply(self.tk.call, what + (sequence, func))
422 else:
423 return apply(self.tk.call, what + (sequence,))
424 def bind(self, sequence=None, func=None, add=None):
425 return self._bind(('bind', self._w), sequence, func, add)
Guido van Rossumef8f8811994-08-08 12:47:33 +0000426 def unbind(self, sequence):
427 self.tk.call('bind', self._w, sequence, '')
Guido van Rossum37dcab11996-05-16 16:00:19 +0000428 def bind_all(self, sequence=None, func=None, add=None):
429 return self._bind(('bind', 'all'), sequence, func, add)
Guido van Rossum761c5ab1995-07-14 15:29:10 +0000430 def unbind_all(self, sequence):
431 self.tk.call('bind', 'all' , sequence, '')
Guido van Rossum37dcab11996-05-16 16:00:19 +0000432 def bind_class(self, className, sequence=None, func=None, add=None):
433 self._bind(('bind', className), sequence, func, add)
Guido van Rossum761c5ab1995-07-14 15:29:10 +0000434 def unbind_class(self, className, sequence):
435 self.tk.call('bind', className , sequence, '')
Guido van Rossum35f67fb1995-08-04 03:50:29 +0000436 def mainloop(self, n=0):
437 self.tk.mainloop(n)
Guido van Rossum18468821994-06-20 07:49:28 +0000438 def quit(self):
439 self.tk.quit()
Guido van Rossum18468821994-06-20 07:49:28 +0000440 def _getints(self, string):
Guido van Rossum45853db1994-06-20 12:19:19 +0000441 if not string: return None
Guido van Rossum7e9394a1995-03-17 16:21:33 +0000442 return tuple(map(self.tk.getint, self.tk.splitlist(string)))
443 def _getdoubles(self, string):
444 if not string: return None
445 return tuple(map(self.tk.getdouble, self.tk.splitlist(string)))
Guido van Rossum18468821994-06-20 07:49:28 +0000446 def _getboolean(self, string):
447 if string:
448 return self.tk.getboolean(string)
Fred Drake3c602d71996-09-27 14:06:54 +0000449 def _displayof(self, displayof):
450 if displayof:
451 return ('-displayof', displayof)
452 if displayof is None:
453 return ('-displayof', self._w)
454 return ()
Guido van Rossum35f67fb1995-08-04 03:50:29 +0000455 def _options(self, cnf, kw = None):
456 if kw:
457 cnf = _cnfmerge((cnf, kw))
458 else:
459 cnf = _cnfmerge(cnf)
Guido van Rossum18468821994-06-20 07:49:28 +0000460 res = ()
461 for k, v in cnf.items():
Fred Drake3c602d71996-09-27 14:06:54 +0000462 if v is not None:
463 if k[-1] == '_': k = k[:-1]
464 if callable(v):
465 v = self._register(v)
466 res = res + ('-'+k, v)
Guido van Rossum18468821994-06-20 07:49:28 +0000467 return res
Guido van Rossum45853db1994-06-20 12:19:19 +0000468 def _nametowidget(self, name):
469 w = self
470 if name[0] == '.':
471 w = w._root()
472 name = name[1:]
Guido van Rossum37dcab11996-05-16 16:00:19 +0000473 find = _string.find
Guido van Rossum45853db1994-06-20 12:19:19 +0000474 while name:
475 i = find(name, '.')
476 if i >= 0:
477 name, tail = name[:i], name[i+1:]
478 else:
479 tail = ''
480 w = w.children[name]
481 name = tail
482 return w
Guido van Rossum18468821994-06-20 07:49:28 +0000483 def _register(self, func, subst=None):
Guido van Rossum37dcab11996-05-16 16:00:19 +0000484 f = CallWrapper(func, subst, self).__call__
Guido van Rossum18468821994-06-20 07:49:28 +0000485 name = `id(f)`
Guido van Rossum37dcab11996-05-16 16:00:19 +0000486 try:
Guido van Rossum18468821994-06-20 07:49:28 +0000487 func = func.im_func
Guido van Rossum37dcab11996-05-16 16:00:19 +0000488 except AttributeError:
489 pass
490 try:
Guido van Rossuma5773dd1995-09-07 19:22:00 +0000491 name = name + func.__name__
Guido van Rossum37dcab11996-05-16 16:00:19 +0000492 except AttributeError:
493 pass
Guido van Rossum18468821994-06-20 07:49:28 +0000494 self.tk.createcommand(name, f)
495 return name
Guido van Rossum9beb9321994-06-27 23:15:31 +0000496 register = _register
Guido van Rossum45853db1994-06-20 12:19:19 +0000497 def _root(self):
498 w = self
499 while w.master: w = w.master
500 return w
Guido van Rossumaec5dc91994-06-27 07:55:12 +0000501 _subst_format = ('%#', '%b', '%f', '%h', '%k',
Guido van Rossum45853db1994-06-20 12:19:19 +0000502 '%s', '%t', '%w', '%x', '%y',
503 '%A', '%E', '%K', '%N', '%W', '%T', '%X', '%Y')
504 def _substitute(self, *args):
505 tk = self.tk
Guido van Rossumaec5dc91994-06-27 07:55:12 +0000506 if len(args) != len(self._subst_format): return args
Guido van Rossum45853db1994-06-20 12:19:19 +0000507 nsign, b, f, h, k, s, t, w, x, y, A, E, K, N, W, T, X, Y = args
508 # Missing: (a, c, d, m, o, v, B, R)
509 e = Event()
510 e.serial = tk.getint(nsign)
511 e.num = tk.getint(b)
512 try: e.focus = tk.getboolean(f)
513 except TclError: pass
514 e.height = tk.getint(h)
515 e.keycode = tk.getint(k)
Guido van Rossum36269991996-05-16 17:11:27 +0000516 # For Visibility events, event state is a string and
517 # not an integer:
518 try:
519 e.state = tk.getint(s)
520 except TclError:
521 e.state = s
Guido van Rossum45853db1994-06-20 12:19:19 +0000522 e.time = tk.getint(t)
523 e.width = tk.getint(w)
524 e.x = tk.getint(x)
525 e.y = tk.getint(y)
526 e.char = A
527 try: e.send_event = tk.getboolean(E)
528 except TclError: pass
529 e.keysym = K
530 e.keysym_num = tk.getint(N)
531 e.type = T
532 e.widget = self._nametowidget(W)
533 e.x_root = tk.getint(X)
534 e.y_root = tk.getint(Y)
535 return (e,)
Guido van Rossuma5773dd1995-09-07 19:22:00 +0000536 def _report_exception(self):
537 import sys
538 exc, val, tb = sys.exc_type, sys.exc_value, sys.exc_traceback
539 root = self._root()
540 root.report_callback_exception(exc, val, tb)
Guido van Rossum18468821994-06-20 07:49:28 +0000541
Guido van Rossuma5773dd1995-09-07 19:22:00 +0000542class CallWrapper:
543 def __init__(self, func, subst, widget):
Guido van Rossum18468821994-06-20 07:49:28 +0000544 self.func = func
545 self.subst = subst
Guido van Rossuma5773dd1995-09-07 19:22:00 +0000546 self.widget = widget
Guido van Rossum18468821994-06-20 07:49:28 +0000547 def __call__(self, *args):
Guido van Rossum18468821994-06-20 07:49:28 +0000548 try:
Guido van Rossuma5773dd1995-09-07 19:22:00 +0000549 if self.subst:
550 args = apply(self.subst, args)
551 return apply(self.func, args)
Guido van Rossum45853db1994-06-20 12:19:19 +0000552 except SystemExit, msg:
553 raise SystemExit, msg
Guido van Rossum18468821994-06-20 07:49:28 +0000554 except:
Guido van Rossuma5773dd1995-09-07 19:22:00 +0000555 self.widget._report_exception()
Guido van Rossum18468821994-06-20 07:49:28 +0000556
557class Wm:
558 def aspect(self,
559 minNumer=None, minDenom=None,
560 maxNumer=None, maxDenom=None):
561 return self._getints(
562 self.tk.call('wm', 'aspect', self._w,
563 minNumer, minDenom,
564 maxNumer, maxDenom))
565 def client(self, name=None):
566 return self.tk.call('wm', 'client', self._w, name)
Fred Drake3c602d71996-09-27 14:06:54 +0000567 def colormapwindows(self, *wlist):
568 args = ('wm', 'colormapwindows', self._w) + _flatten(wlist)
569 return map(self._nametowidget, apply(self.tk.call, args))
Guido van Rossum18468821994-06-20 07:49:28 +0000570 def command(self, value=None):
571 return self.tk.call('wm', 'command', self._w, value)
572 def deiconify(self):
573 return self.tk.call('wm', 'deiconify', self._w)
574 def focusmodel(self, model=None):
575 return self.tk.call('wm', 'focusmodel', self._w, model)
576 def frame(self):
577 return self.tk.call('wm', 'frame', self._w)
578 def geometry(self, newGeometry=None):
579 return self.tk.call('wm', 'geometry', self._w, newGeometry)
580 def grid(self,
581 baseWidht=None, baseHeight=None,
582 widthInc=None, heightInc=None):
583 return self._getints(self.tk.call(
584 'wm', 'grid', self._w,
585 baseWidht, baseHeight, widthInc, heightInc))
586 def group(self, pathName=None):
587 return self.tk.call('wm', 'group', self._w, pathName)
588 def iconbitmap(self, bitmap=None):
589 return self.tk.call('wm', 'iconbitmap', self._w, bitmap)
590 def iconify(self):
591 return self.tk.call('wm', 'iconify', self._w)
592 def iconmask(self, bitmap=None):
593 return self.tk.call('wm', 'iconmask', self._w, bitmap)
594 def iconname(self, newName=None):
595 return self.tk.call('wm', 'iconname', self._w, newName)
596 def iconposition(self, x=None, y=None):
597 return self._getints(self.tk.call(
598 'wm', 'iconposition', self._w, x, y))
599 def iconwindow(self, pathName=None):
600 return self.tk.call('wm', 'iconwindow', self._w, pathName)
601 def maxsize(self, width=None, height=None):
602 return self._getints(self.tk.call(
603 'wm', 'maxsize', self._w, width, height))
604 def minsize(self, width=None, height=None):
605 return self._getints(self.tk.call(
606 'wm', 'minsize', self._w, width, height))
607 def overrideredirect(self, boolean=None):
608 return self._getboolean(self.tk.call(
609 'wm', 'overrideredirect', self._w, boolean))
610 def positionfrom(self, who=None):
611 return self.tk.call('wm', 'positionfrom', self._w, who)
612 def protocol(self, name=None, func=None):
Guido van Rossum37dcab11996-05-16 16:00:19 +0000613 if callable(func):
Guido van Rossum18468821994-06-20 07:49:28 +0000614 command = self._register(func)
615 else:
616 command = func
617 return self.tk.call(
618 'wm', 'protocol', self._w, name, command)
Guido van Rossum37dcab11996-05-16 16:00:19 +0000619 def resizable(self, width=None, height=None):
620 return self.tk.call('wm', 'resizable', self._w, width, height)
Guido van Rossum18468821994-06-20 07:49:28 +0000621 def sizefrom(self, who=None):
622 return self.tk.call('wm', 'sizefrom', self._w, who)
623 def state(self):
624 return self.tk.call('wm', 'state', self._w)
625 def title(self, string=None):
626 return self.tk.call('wm', 'title', self._w, string)
627 def transient(self, master=None):
628 return self.tk.call('wm', 'transient', self._w, master)
629 def withdraw(self):
630 return self.tk.call('wm', 'withdraw', self._w)
631
632class Tk(Misc, Wm):
633 _w = '.'
634 def __init__(self, screenName=None, baseName=None, className='Tk'):
Guido van Rossuma5773dd1995-09-07 19:22:00 +0000635 global _default_root
Guido van Rossum45853db1994-06-20 12:19:19 +0000636 self.master = None
637 self.children = {}
Guido van Rossum18468821994-06-20 07:49:28 +0000638 if baseName is None:
639 import sys, os
640 baseName = os.path.basename(sys.argv[0])
Fred Drakecab3c3b1996-10-06 17:55:20 +0000641 baseName, ext = os.path.splitext(baseName)
642 if ext not in ('.py', 'pyc'): baseName = baseName + ext
Guido van Rossum37dcab11996-05-16 16:00:19 +0000643 self.tk = tkinter.create(screenName, baseName, className)
644 try:
645 # Disable event scanning except for Command-Period
646 import MacOS
647 MacOS.EnableAppswitch(0)
648 except ImportError:
649 pass
650 else:
651 # Work around nasty MacTk bug
652 self.update()
Guido van Rossumf7f79ac1995-10-07 19:08:37 +0000653 # Version sanity checks
654 tk_version = self.tk.getvar('tk_version')
Guido van Rossum37dcab11996-05-16 16:00:19 +0000655 if tk_version != tkinter.TK_VERSION:
Guido van Rossumf7f79ac1995-10-07 19:08:37 +0000656 raise RuntimeError, \
657 "tk.h version (%s) doesn't match libtk.a version (%s)" \
Guido van Rossum37dcab11996-05-16 16:00:19 +0000658 % (tkinter.TK_VERSION, tk_version)
Guido van Rossumf7f79ac1995-10-07 19:08:37 +0000659 tcl_version = self.tk.getvar('tcl_version')
Guido van Rossum37dcab11996-05-16 16:00:19 +0000660 if tcl_version != tkinter.TCL_VERSION:
Guido van Rossumf7f79ac1995-10-07 19:08:37 +0000661 raise RuntimeError, \
662 "tcl.h version (%s) doesn't match libtcl.a version (%s)" \
Guido van Rossum37dcab11996-05-16 16:00:19 +0000663 % (tkinter.TCL_VERSION, tcl_version)
Guido van Rossumf7f79ac1995-10-07 19:08:37 +0000664 if TkVersion < 4.0:
Guido van Rossum37dcab11996-05-16 16:00:19 +0000665 raise RuntimeError, \
666 "Tk 4.0 or higher is required; found Tk %s" \
667 % str(TkVersion)
Guido van Rossum45853db1994-06-20 12:19:19 +0000668 self.tk.createcommand('tkerror', _tkerror)
Guido van Rossum97aeca11994-07-07 13:12:12 +0000669 self.tk.createcommand('exit', _exit)
Guido van Rossum27b77a41994-07-12 15:52:32 +0000670 self.readprofile(baseName, className)
Guido van Rossuma5773dd1995-09-07 19:22:00 +0000671 if not _default_root:
672 _default_root = self
Guido van Rossum45853db1994-06-20 12:19:19 +0000673 def destroy(self):
674 for c in self.children.values(): c.destroy()
Guido van Rossum45853db1994-06-20 12:19:19 +0000675 self.tk.call('destroy', self._w)
Guido van Rossum18468821994-06-20 07:49:28 +0000676 def __str__(self):
Guido van Rossum45853db1994-06-20 12:19:19 +0000677 return self._w
Guido van Rossum27b77a41994-07-12 15:52:32 +0000678 def readprofile(self, baseName, className):
Guido van Rossum37dcab11996-05-16 16:00:19 +0000679 import os
Guido van Rossum27b77a41994-07-12 15:52:32 +0000680 if os.environ.has_key('HOME'): home = os.environ['HOME']
681 else: home = os.curdir
682 class_tcl = os.path.join(home, '.%s.tcl' % className)
683 class_py = os.path.join(home, '.%s.py' % className)
684 base_tcl = os.path.join(home, '.%s.tcl' % baseName)
685 base_py = os.path.join(home, '.%s.py' % baseName)
686 dir = {'self': self}
687 exec 'from Tkinter import *' in dir
688 if os.path.isfile(class_tcl):
689 print 'source', `class_tcl`
690 self.tk.call('source', class_tcl)
691 if os.path.isfile(class_py):
692 print 'execfile', `class_py`
693 execfile(class_py, dir)
694 if os.path.isfile(base_tcl):
695 print 'source', `base_tcl`
696 self.tk.call('source', base_tcl)
697 if os.path.isfile(base_py):
698 print 'execfile', `base_py`
699 execfile(base_py, dir)
Guido van Rossuma5773dd1995-09-07 19:22:00 +0000700 def report_callback_exception(self, exc, val, tb):
701 import traceback
702 print "Exception in Tkinter callback"
703 traceback.print_exception(exc, val, tb)
Guido van Rossum18468821994-06-20 07:49:28 +0000704
705class Pack:
Guido van Rossum35f67fb1995-08-04 03:50:29 +0000706 def config(self, cnf={}, **kw):
Guido van Rossum18468821994-06-20 07:49:28 +0000707 apply(self.tk.call,
708 ('pack', 'configure', self._w)
Guido van Rossum35f67fb1995-08-04 03:50:29 +0000709 + self._options(cnf, kw))
Guido van Rossum37dcab11996-05-16 16:00:19 +0000710 configure = config
Guido van Rossum18468821994-06-20 07:49:28 +0000711 pack = config
712 def __setitem__(self, key, value):
713 Pack.config({key: value})
714 def forget(self):
715 self.tk.call('pack', 'forget', self._w)
Guido van Rossum37dcab11996-05-16 16:00:19 +0000716 pack_forget = forget
717 def info(self):
Guido van Rossum69170c51994-07-11 15:21:31 +0000718 words = self.tk.splitlist(
Guido van Rossum37dcab11996-05-16 16:00:19 +0000719 self.tk.call('pack', 'info', self._w))
Guido van Rossum69170c51994-07-11 15:21:31 +0000720 dict = {}
721 for i in range(0, len(words), 2):
722 key = words[i][1:]
723 value = words[i+1]
Guido van Rossuma5f875f1996-05-16 17:50:07 +0000724 if value[:1] == '.':
Guido van Rossum69170c51994-07-11 15:21:31 +0000725 value = self._nametowidget(value)
726 dict[key] = value
727 return dict
Guido van Rossum37dcab11996-05-16 16:00:19 +0000728 pack_info = info
Guido van Rossum5505d561994-12-30 17:16:35 +0000729 _noarg_ = ['_noarg_']
730 def propagate(self, flag=_noarg_):
Guido van Rossuma5773dd1995-09-07 19:22:00 +0000731 if flag is Pack._noarg_:
Guido van Rossum18468821994-06-20 07:49:28 +0000732 return self._getboolean(self.tk.call(
733 'pack', 'propagate', self._w))
Guido van Rossum5505d561994-12-30 17:16:35 +0000734 else:
735 self.tk.call('pack', 'propagate', self._w, flag)
Guido van Rossum37dcab11996-05-16 16:00:19 +0000736 pack_propagate = propagate
Guido van Rossum18468821994-06-20 07:49:28 +0000737 def slaves(self):
Guido van Rossum45853db1994-06-20 12:19:19 +0000738 return map(self._nametowidget,
739 self.tk.splitlist(
740 self.tk.call('pack', 'slaves', self._w)))
Guido van Rossum37dcab11996-05-16 16:00:19 +0000741 pack_slaves = slaves
Guido van Rossum18468821994-06-20 07:49:28 +0000742
743class Place:
Guido van Rossum35f67fb1995-08-04 03:50:29 +0000744 def config(self, cnf={}, **kw):
Guido van Rossum37dcab11996-05-16 16:00:19 +0000745 for k in ['in_']:
746 if kw.has_key(k):
747 kw[k[:-1]] = kw[k]
748 del kw[k]
Guido van Rossum18468821994-06-20 07:49:28 +0000749 apply(self.tk.call,
750 ('place', 'configure', self._w)
Guido van Rossum35f67fb1995-08-04 03:50:29 +0000751 + self._options(cnf, kw))
Guido van Rossum37dcab11996-05-16 16:00:19 +0000752 configure = config
Guido van Rossum18468821994-06-20 07:49:28 +0000753 place = config
754 def __setitem__(self, key, value):
755 Place.config({key: value})
756 def forget(self):
757 self.tk.call('place', 'forget', self._w)
Guido van Rossum37dcab11996-05-16 16:00:19 +0000758 place_forget = forget
Guido van Rossum18468821994-06-20 07:49:28 +0000759 def info(self):
Guido van Rossum63e39ae1996-05-16 17:53:48 +0000760 words = self.tk.splitlist(
761 self.tk.call('place', 'info', self._w))
762 dict = {}
763 for i in range(0, len(words), 2):
764 key = words[i][1:]
765 value = words[i+1]
766 if value[:1] == '.':
767 value = self._nametowidget(value)
768 dict[key] = value
769 return dict
Guido van Rossum37dcab11996-05-16 16:00:19 +0000770 place_info = info
Guido van Rossum18468821994-06-20 07:49:28 +0000771 def slaves(self):
Guido van Rossum45853db1994-06-20 12:19:19 +0000772 return map(self._nametowidget,
773 self.tk.splitlist(
774 self.tk.call(
775 'place', 'slaves', self._w)))
Guido van Rossum37dcab11996-05-16 16:00:19 +0000776 place_slaves = slaves
Guido van Rossum18468821994-06-20 07:49:28 +0000777
Guido van Rossum37dcab11996-05-16 16:00:19 +0000778class Grid:
Guido van Rossum422cc7f1996-05-21 20:30:07 +0000779 # Thanks to Masazumi Yoshikawa (yosikawa@isi.edu)
Guido van Rossum37dcab11996-05-16 16:00:19 +0000780 def config(self, cnf={}, **kw):
781 apply(self.tk.call,
782 ('grid', 'configure', self._w)
783 + self._options(cnf, kw))
784 grid = config
785 def __setitem__(self, key, value):
786 Grid.config({key: value})
787 def bbox(self, column, row):
788 return self._getints(
789 self.tk.call(
790 'grid', 'bbox', self._w, column, row)) or None
791 grid_bbox = bbox
Guido van Rossum422cc7f1996-05-21 20:30:07 +0000792 def columnconfigure(self, index, cnf={}, **kw):
793 if type(cnf) is not DictionaryType and not kw:
794 options = self._options({cnf: None})
795 else:
796 options = self._options(cnf, kw)
Guido van Rossum37dcab11996-05-16 16:00:19 +0000797 res = apply(self.tk.call,
Guido van Rossum422cc7f1996-05-21 20:30:07 +0000798 ('grid', 'columnconfigure', self._w, index)
799 + options)
800 if options == ('-minsize', None):
801 return self.tk.getint(res) or None
802 elif options == ('-weight', None):
803 return self.tk.getdouble(res) or None
Guido van Rossum37dcab11996-05-16 16:00:19 +0000804 def forget(self):
805 self.tk.call('grid', 'forget', self._w)
806 grid_forget = forget
807 def info(self):
808 words = self.tk.splitlist(
809 self.tk.call('grid', 'info', self._w))
810 dict = {}
811 for i in range(0, len(words), 2):
812 key = words[i][1:]
813 value = words[i+1]
Guido van Rossuma5f875f1996-05-16 17:50:07 +0000814 if value[:1] == '.':
Guido van Rossum37dcab11996-05-16 16:00:19 +0000815 value = self._nametowidget(value)
816 dict[key] = value
817 return dict
818 grid_info = info
819 def location(self, x, y):
820 return self._getints(
821 self.tk.call(
822 'grid', 'location', self._w, x, y)) or None
823 _noarg_ = ['_noarg_']
824 def propagate(self, flag=_noarg_):
825 if flag is Grid._noarg_:
826 return self._getboolean(self.tk.call(
827 'grid', 'propagate', self._w))
828 else:
829 self.tk.call('grid', 'propagate', self._w, flag)
830 grid_propagate = propagate
Guido van Rossum422cc7f1996-05-21 20:30:07 +0000831 def rowconfigure(self, index, cnf={}, **kw):
832 if type(cnf) is not DictionaryType and not kw:
833 options = self._options({cnf: None})
834 else:
835 options = self._options(cnf, kw)
Guido van Rossum37dcab11996-05-16 16:00:19 +0000836 res = apply(self.tk.call,
Guido van Rossum422cc7f1996-05-21 20:30:07 +0000837 ('grid', 'rowconfigure', self._w, index)
838 + options)
839 if options == ('-minsize', None):
840 return self.tk.getint(res) or None
841 elif options == ('-weight', None):
842 return self.tk.getdouble(res) or None
Guido van Rossum37dcab11996-05-16 16:00:19 +0000843 def size(self):
844 return self._getints(
845 self.tk.call('grid', 'size', self._w)) or None
846 def slaves(self, *args):
847 return map(self._nametowidget,
848 self.tk.splitlist(
849 apply(self.tk.call,
850 ('grid', 'slaves', self._w) + args)))
851 grid_slaves = slaves
852
853class Widget(Misc, Pack, Place, Grid):
Guido van Rossumaec5dc91994-06-27 07:55:12 +0000854 def _setup(self, master, cnf):
Guido van Rossum45853db1994-06-20 12:19:19 +0000855 global _default_root
Guido van Rossum18468821994-06-20 07:49:28 +0000856 if not master:
Guido van Rossum45853db1994-06-20 12:19:19 +0000857 if not _default_root:
858 _default_root = Tk()
859 master = _default_root
860 if not _default_root:
861 _default_root = master
Guido van Rossum18468821994-06-20 07:49:28 +0000862 self.master = master
863 self.tk = master.tk
864 if cnf.has_key('name'):
865 name = cnf['name']
866 del cnf['name']
867 else:
868 name = `id(self)`
Guido van Rossum45853db1994-06-20 12:19:19 +0000869 self._name = name
Guido van Rossum35f67fb1995-08-04 03:50:29 +0000870 if master._w=='.':
Guido van Rossum18468821994-06-20 07:49:28 +0000871 self._w = '.' + name
872 else:
873 self._w = master._w + '.' + name
Guido van Rossumaec5dc91994-06-27 07:55:12 +0000874 self.children = {}
875 if self.master.children.has_key(self._name):
Guido van Rossum2dcf5291994-07-06 09:23:20 +0000876 self.master.children[self._name].destroy()
Guido van Rossumaec5dc91994-06-27 07:55:12 +0000877 self.master.children[self._name] = self
Guido van Rossum35f67fb1995-08-04 03:50:29 +0000878 def __init__(self, master, widgetName, cnf={}, kw={}, extra=()):
879 if kw:
880 cnf = _cnfmerge((cnf, kw))
Guido van Rossum18468821994-06-20 07:49:28 +0000881 self.widgetName = widgetName
Guido van Rossum761c5ab1995-07-14 15:29:10 +0000882 Widget._setup(self, master, cnf)
Guido van Rossumad8b3ba1996-07-21 03:05:05 +0000883 classes = []
884 for k in cnf.keys():
885 if type(k) is ClassType:
886 classes.append((k, cnf[k]))
887 del cnf[k]
Guido van Rossum37dcab11996-05-16 16:00:19 +0000888 apply(self.tk.call,
889 (widgetName, self._w) + extra + self._options(cnf))
Guido van Rossumad8b3ba1996-07-21 03:05:05 +0000890 for k, v in classes:
891 k.config(self, v)
Guido van Rossum35f67fb1995-08-04 03:50:29 +0000892 def config(self, cnf=None, **kw):
893 # XXX ought to generalize this so tag_config etc. can use it
894 if kw:
895 cnf = _cnfmerge((cnf, kw))
Guido van Rossum37dcab11996-05-16 16:00:19 +0000896 elif cnf:
Guido van Rossum35f67fb1995-08-04 03:50:29 +0000897 cnf = _cnfmerge(cnf)
Guido van Rossum9b68fd91994-06-23 07:40:14 +0000898 if cnf is None:
899 cnf = {}
900 for x in self.tk.split(
901 self.tk.call(self._w, 'configure')):
902 cnf[x[0][1:]] = (x[0][1:],) + x[1:]
903 return cnf
Guido van Rossum37dcab11996-05-16 16:00:19 +0000904 if type(cnf) is StringType:
Guido van Rossum9b68fd91994-06-23 07:40:14 +0000905 x = self.tk.split(self.tk.call(
906 self._w, 'configure', '-'+cnf))
907 return (x[0][1:],) + x[1:]
Guido van Rossum18468821994-06-20 07:49:28 +0000908 apply(self.tk.call, (self._w, 'configure')
909 + self._options(cnf))
Guido van Rossum37dcab11996-05-16 16:00:19 +0000910 configure = config
Guido van Rossum422cc7f1996-05-21 20:30:07 +0000911 def cget(self, key):
Guido van Rossum37dcab11996-05-16 16:00:19 +0000912 return self.tk.call(self._w, 'cget', '-' + key)
Guido van Rossum422cc7f1996-05-21 20:30:07 +0000913 __getitem__ = cget
Guido van Rossum18468821994-06-20 07:49:28 +0000914 def __setitem__(self, key, value):
915 Widget.config(self, {key: value})
Guido van Rossum9b68fd91994-06-23 07:40:14 +0000916 def keys(self):
917 return map(lambda x: x[0][1:],
918 self.tk.split(self.tk.call(self._w, 'configure')))
Guido van Rossum18468821994-06-20 07:49:28 +0000919 def __str__(self):
920 return self._w
Guido van Rossum45853db1994-06-20 12:19:19 +0000921 def destroy(self):
922 for c in self.children.values(): c.destroy()
Guido van Rossumf023ab01994-08-30 12:13:44 +0000923 if self.master.children.has_key(self._name):
924 del self.master.children[self._name]
Guido van Rossum18468821994-06-20 07:49:28 +0000925 self.tk.call('destroy', self._w)
Guido van Rossum18468821994-06-20 07:49:28 +0000926 def _do(self, name, args=()):
Guido van Rossum761c5ab1995-07-14 15:29:10 +0000927 return apply(self.tk.call, (self._w, name) + args)
Guido van Rossum18468821994-06-20 07:49:28 +0000928
929class Toplevel(Widget, Wm):
Guido van Rossum35f67fb1995-08-04 03:50:29 +0000930 def __init__(self, master=None, cnf={}, **kw):
931 if kw:
932 cnf = _cnfmerge((cnf, kw))
Guido van Rossum18468821994-06-20 07:49:28 +0000933 extra = ()
Guido van Rossum37dcab11996-05-16 16:00:19 +0000934 for wmkey in ['screen', 'class_', 'class', 'visual',
935 'colormap']:
936 if cnf.has_key(wmkey):
937 val = cnf[wmkey]
938 # TBD: a hack needed because some keys
939 # are not valid as keyword arguments
940 if wmkey[-1] == '_': opt = '-'+wmkey[:-1]
941 else: opt = '-'+wmkey
942 extra = extra + (opt, val)
943 del cnf[wmkey]
Guido van Rossum35f67fb1995-08-04 03:50:29 +0000944 Widget.__init__(self, master, 'toplevel', cnf, {}, extra)
Guido van Rossum45853db1994-06-20 12:19:19 +0000945 root = self._root()
946 self.iconname(root.iconname())
947 self.title(root.title())
Guido van Rossum18468821994-06-20 07:49:28 +0000948
949class Button(Widget):
Guido van Rossum35f67fb1995-08-04 03:50:29 +0000950 def __init__(self, master=None, cnf={}, **kw):
951 Widget.__init__(self, master, 'button', cnf, kw)
Guido van Rossum761c5ab1995-07-14 15:29:10 +0000952 def tkButtonEnter(self, *dummy):
953 self.tk.call('tkButtonEnter', self._w)
954 def tkButtonLeave(self, *dummy):
955 self.tk.call('tkButtonLeave', self._w)
956 def tkButtonDown(self, *dummy):
957 self.tk.call('tkButtonDown', self._w)
958 def tkButtonUp(self, *dummy):
959 self.tk.call('tkButtonUp', self._w)
Guido van Rossum36269991996-05-16 17:11:27 +0000960 def tkButtonInvoke(self, *dummy):
961 self.tk.call('tkButtonInvoke', self._w)
Guido van Rossum18468821994-06-20 07:49:28 +0000962 def flash(self):
963 self.tk.call(self._w, 'flash')
964 def invoke(self):
965 self.tk.call(self._w, 'invoke')
966
967# Indices:
Guido van Rossum35f67fb1995-08-04 03:50:29 +0000968# XXX I don't like these -- take them away
Guido van Rossum18468821994-06-20 07:49:28 +0000969def AtEnd():
970 return 'end'
Guido van Rossum1e9e4001994-06-20 09:09:51 +0000971def AtInsert(*args):
972 s = 'insert'
973 for a in args:
974 if a: s = s + (' ' + a)
975 return s
Guido van Rossum18468821994-06-20 07:49:28 +0000976def AtSelFirst():
977 return 'sel.first'
978def AtSelLast():
979 return 'sel.last'
980def At(x, y=None):
Guido van Rossum5e0c25b1994-07-12 09:04:41 +0000981 if y is None:
982 return '@' + `x`
Guido van Rossum18468821994-06-20 07:49:28 +0000983 else:
Guido van Rossum5e0c25b1994-07-12 09:04:41 +0000984 return '@' + `x` + ',' + `y`
Guido van Rossum18468821994-06-20 07:49:28 +0000985
986class Canvas(Widget):
Guido van Rossum35f67fb1995-08-04 03:50:29 +0000987 def __init__(self, master=None, cnf={}, **kw):
988 Widget.__init__(self, master, 'canvas', cnf, kw)
Guido van Rossum18468821994-06-20 07:49:28 +0000989 def addtag(self, *args):
990 self._do('addtag', args)
Guido van Rossum5c8c91b1996-08-22 23:18:09 +0000991 def addtag_above(self, newtag, tagOrId):
992 self.addtag(newtag, 'above', tagOrId)
993 def addtag_all(self, newtag):
994 self.addtag(newtag, 'all')
995 def addtag_below(self, newtag, tagOrId):
996 self.addtag(newtag, 'below', tagOrId)
997 def addtag_closest(self, newtag, x, y, halo=None, start=None):
998 self.addtag(newtag, 'closest', x, y, halo, start)
999 def addtag_enclosed(self, newtag, x1, y1, x2, y2):
1000 self.addtag(newtag, 'enclosed', x1, y1, x2, y2)
1001 def addtag_overlapping(self, newtag, x1, y1, x2, y2):
1002 self.addtag(newtag, 'overlapping', x1, y1, x2, y2)
1003 def addtag_withtag(self, newtag, tagOrId):
1004 self.addtag(newtag, 'withtag', tagOrId)
Guido van Rossum18468821994-06-20 07:49:28 +00001005 def bbox(self, *args):
Guido van Rossum9b68fd91994-06-23 07:40:14 +00001006 return self._getints(self._do('bbox', args)) or None
Guido van Rossumef8f8811994-08-08 12:47:33 +00001007 def tag_unbind(self, tagOrId, sequence):
1008 self.tk.call(self._w, 'bind', tagOrId, sequence, '')
Guido van Rossum37dcab11996-05-16 16:00:19 +00001009 def tag_bind(self, tagOrId, sequence=None, func=None, add=None):
Guido van Rossum421bb0e1996-07-21 02:19:32 +00001010 return self._bind((self._w, 'bind', tagOrId),
Guido van Rossum37dcab11996-05-16 16:00:19 +00001011 sequence, func, add)
Guido van Rossum18468821994-06-20 07:49:28 +00001012 def canvasx(self, screenx, gridspacing=None):
Guido van Rossum761c5ab1995-07-14 15:29:10 +00001013 return self.tk.getdouble(self.tk.call(
Guido van Rossum18468821994-06-20 07:49:28 +00001014 self._w, 'canvasx', screenx, gridspacing))
1015 def canvasy(self, screeny, gridspacing=None):
Guido van Rossum761c5ab1995-07-14 15:29:10 +00001016 return self.tk.getdouble(self.tk.call(
Guido van Rossum18468821994-06-20 07:49:28 +00001017 self._w, 'canvasy', screeny, gridspacing))
1018 def coords(self, *args):
Guido van Rossumc8b47911996-07-30 16:31:32 +00001019 return map(self.tk.getdouble,
Guido van Rossum9afdabf1996-07-30 20:16:21 +00001020 self.tk.splitlist(self._do('coords', args)))
Guido van Rossum37dcab11996-05-16 16:00:19 +00001021 def _create(self, itemType, args, kw): # Args: (val, val, ..., cnf={})
Guido van Rossum08a40381994-06-21 11:44:21 +00001022 args = _flatten(args)
Guido van Rossum18468821994-06-20 07:49:28 +00001023 cnf = args[-1]
Guido van Rossum2dcf5291994-07-06 09:23:20 +00001024 if type(cnf) in (DictionaryType, TupleType):
Guido van Rossum18468821994-06-20 07:49:28 +00001025 args = args[:-1]
1026 else:
1027 cnf = {}
Guido van Rossum2dcf5291994-07-06 09:23:20 +00001028 return self.tk.getint(apply(
1029 self.tk.call,
1030 (self._w, 'create', itemType)
Guido van Rossum35f67fb1995-08-04 03:50:29 +00001031 + args + self._options(cnf, kw)))
1032 def create_arc(self, *args, **kw):
1033 return self._create('arc', args, kw)
1034 def create_bitmap(self, *args, **kw):
1035 return self._create('bitmap', args, kw)
1036 def create_image(self, *args, **kw):
1037 return self._create('image', args, kw)
1038 def create_line(self, *args, **kw):
1039 return self._create('line', args, kw)
1040 def create_oval(self, *args, **kw):
1041 return self._create('oval', args, kw)
1042 def create_polygon(self, *args, **kw):
1043 return self._create('polygon', args, kw)
1044 def create_rectangle(self, *args, **kw):
1045 return self._create('rectangle', args, kw)
1046 def create_text(self, *args, **kw):
1047 return self._create('text', args, kw)
1048 def create_window(self, *args, **kw):
1049 return self._create('window', args, kw)
Guido van Rossum18468821994-06-20 07:49:28 +00001050 def dchars(self, *args):
1051 self._do('dchars', args)
1052 def delete(self, *args):
1053 self._do('delete', args)
1054 def dtag(self, *args):
1055 self._do('dtag', args)
1056 def find(self, *args):
Guido van Rossum37dcab11996-05-16 16:00:19 +00001057 return self._getints(self._do('find', args)) or ()
Guido van Rossum9b68fd91994-06-23 07:40:14 +00001058 def find_above(self, tagOrId):
1059 return self.find('above', tagOrId)
1060 def find_all(self):
1061 return self.find('all')
1062 def find_below(self, tagOrId):
1063 return self.find('below', tagOrId)
1064 def find_closest(self, x, y, halo=None, start=None):
1065 return self.find('closest', x, y, halo, start)
1066 def find_enclosed(self, x1, y1, x2, y2):
1067 return self.find('enclosed', x1, y1, x2, y2)
1068 def find_overlapping(self, x1, y1, x2, y2):
1069 return self.find('overlapping', x1, y1, x2, y2)
1070 def find_withtag(self, tagOrId):
1071 return self.find('withtag', tagOrId)
Guido van Rossum18468821994-06-20 07:49:28 +00001072 def focus(self, *args):
1073 return self._do('focus', args)
1074 def gettags(self, *args):
1075 return self.tk.splitlist(self._do('gettags', args))
1076 def icursor(self, *args):
1077 self._do('icursor', args)
1078 def index(self, *args):
1079 return self.tk.getint(self._do('index', args))
1080 def insert(self, *args):
1081 self._do('insert', args)
Guido van Rossum37dcab11996-05-16 16:00:19 +00001082 def itemcget(self, tagOrId, option):
1083 return self._do('itemcget', (tagOrId, '-'+option))
Guido van Rossum35f67fb1995-08-04 03:50:29 +00001084 def itemconfig(self, tagOrId, cnf=None, **kw):
1085 if cnf is None and not kw:
Guido van Rossum9b68fd91994-06-23 07:40:14 +00001086 cnf = {}
1087 for x in self.tk.split(
1088 self._do('itemconfigure', (tagOrId))):
1089 cnf[x[0][1:]] = (x[0][1:],) + x[1:]
1090 return cnf
Guido van Rossum35f67fb1995-08-04 03:50:29 +00001091 if type(cnf) == StringType and not kw:
Guido van Rossum9b68fd91994-06-23 07:40:14 +00001092 x = self.tk.split(self._do('itemconfigure',
1093 (tagOrId, '-'+cnf,)))
1094 return (x[0][1:],) + x[1:]
Guido van Rossum35f67fb1995-08-04 03:50:29 +00001095 self._do('itemconfigure', (tagOrId,)
1096 + self._options(cnf, kw))
Guido van Rossum37dcab11996-05-16 16:00:19 +00001097 itemconfigure = itemconfig
Guido van Rossum18468821994-06-20 07:49:28 +00001098 def lower(self, *args):
1099 self._do('lower', args)
1100 def move(self, *args):
1101 self._do('move', args)
Guido van Rossum35f67fb1995-08-04 03:50:29 +00001102 def postscript(self, cnf={}, **kw):
1103 return self._do('postscript', self._options(cnf, kw))
Guido van Rossum18468821994-06-20 07:49:28 +00001104 def tkraise(self, *args):
1105 self._do('raise', args)
Guido van Rossum5e8d3721994-06-20 08:12:01 +00001106 lift = tkraise
Guido van Rossum18468821994-06-20 07:49:28 +00001107 def scale(self, *args):
1108 self._do('scale', args)
1109 def scan_mark(self, x, y):
1110 self.tk.call(self._w, 'scan', 'mark', x, y)
1111 def scan_dragto(self, x, y):
1112 self.tk.call(self._w, 'scan', 'dragto', x, y)
1113 def select_adjust(self, tagOrId, index):
Guido van Rossum08a40381994-06-21 11:44:21 +00001114 self.tk.call(self._w, 'select', 'adjust', tagOrId, index)
Guido van Rossum18468821994-06-20 07:49:28 +00001115 def select_clear(self):
Guido van Rossum37dcab11996-05-16 16:00:19 +00001116 self.tk.call(self._w, 'select', 'clear')
Guido van Rossum18468821994-06-20 07:49:28 +00001117 def select_from(self, tagOrId, index):
Guido van Rossum761c5ab1995-07-14 15:29:10 +00001118 self.tk.call(self._w, 'select', 'set', tagOrId, index)
Guido van Rossum18468821994-06-20 07:49:28 +00001119 def select_item(self):
1120 self.tk.call(self._w, 'select', 'item')
1121 def select_to(self, tagOrId, index):
Guido van Rossum08a40381994-06-21 11:44:21 +00001122 self.tk.call(self._w, 'select', 'to', tagOrId, index)
Guido van Rossum18468821994-06-20 07:49:28 +00001123 def type(self, tagOrId):
Guido van Rossum08a40381994-06-21 11:44:21 +00001124 return self.tk.call(self._w, 'type', tagOrId) or None
Guido van Rossum761c5ab1995-07-14 15:29:10 +00001125 def xview(self, *args):
Guido van Rossum37dcab11996-05-16 16:00:19 +00001126 if not args:
1127 return self._getdoubles(self.tk.call(self._w, 'xview'))
Guido van Rossum761c5ab1995-07-14 15:29:10 +00001128 apply(self.tk.call, (self._w, 'xview')+args)
1129 def yview(self, *args):
Guido van Rossum37dcab11996-05-16 16:00:19 +00001130 if not args:
1131 return self._getdoubles(self.tk.call(self._w, 'yview'))
Guido van Rossum761c5ab1995-07-14 15:29:10 +00001132 apply(self.tk.call, (self._w, 'yview')+args)
Guido van Rossum18468821994-06-20 07:49:28 +00001133
1134class Checkbutton(Widget):
Guido van Rossum35f67fb1995-08-04 03:50:29 +00001135 def __init__(self, master=None, cnf={}, **kw):
1136 Widget.__init__(self, master, 'checkbutton', cnf, kw)
Guido van Rossum18468821994-06-20 07:49:28 +00001137 def deselect(self):
1138 self.tk.call(self._w, 'deselect')
1139 def flash(self):
1140 self.tk.call(self._w, 'flash')
1141 def invoke(self):
1142 self.tk.call(self._w, 'invoke')
1143 def select(self):
1144 self.tk.call(self._w, 'select')
1145 def toggle(self):
1146 self.tk.call(self._w, 'toggle')
1147
1148class Entry(Widget):
Guido van Rossum35f67fb1995-08-04 03:50:29 +00001149 def __init__(self, master=None, cnf={}, **kw):
1150 Widget.__init__(self, master, 'entry', cnf, kw)
Guido van Rossum18468821994-06-20 07:49:28 +00001151 def delete(self, first, last=None):
1152 self.tk.call(self._w, 'delete', first, last)
1153 def get(self):
1154 return self.tk.call(self._w, 'get')
1155 def icursor(self, index):
1156 self.tk.call(self._w, 'icursor', index)
1157 def index(self, index):
1158 return self.tk.getint(self.tk.call(
1159 self._w, 'index', index))
1160 def insert(self, index, string):
1161 self.tk.call(self._w, 'insert', index, string)
1162 def scan_mark(self, x):
1163 self.tk.call(self._w, 'scan', 'mark', x)
1164 def scan_dragto(self, x):
1165 self.tk.call(self._w, 'scan', 'dragto', x)
Guido van Rossum422cc7f1996-05-21 20:30:07 +00001166 def selection_adjust(self, index):
1167 self.tk.call(self._w, 'selection', 'adjust', index)
1168 select_adjust = selection_adjust
1169 def selection_clear(self):
1170 self.tk.call(self._w, 'selection', 'clear')
1171 select_clear = selection_clear
1172 def selection_from(self, index):
Guido van Rossum42b78e61996-09-06 14:20:23 +00001173 self.tk.call(self._w, 'selection', 'from', index)
Guido van Rossum422cc7f1996-05-21 20:30:07 +00001174 select_from = selection_from
1175 def selection_present(self):
Guido van Rossum1d59df21995-08-11 14:21:06 +00001176 return self.tk.getboolean(
Guido van Rossum422cc7f1996-05-21 20:30:07 +00001177 self.tk.call(self._w, 'selection', 'present'))
1178 select_present = selection_present
1179 def selection_range(self, start, end):
1180 self.tk.call(self._w, 'selection', 'range', start, end)
1181 select_range = selection_range
1182 def selection_to(self, index):
1183 self.tk.call(self._w, 'selection', 'to', index)
1184 select_to = selection_to
1185 def xview(self, index):
1186 self.tk.call(self._w, 'xview', index)
1187 def xview_moveto(self, fraction):
1188 self.tk.call(self._w, 'xview', 'moveto', fraction)
1189 def xview_scroll(self, number, what):
1190 self.tk.call(self._w, 'xview', 'scroll', number, what)
Guido van Rossum18468821994-06-20 07:49:28 +00001191
1192class Frame(Widget):
Guido van Rossum35f67fb1995-08-04 03:50:29 +00001193 def __init__(self, master=None, cnf={}, **kw):
1194 cnf = _cnfmerge((cnf, kw))
Guido van Rossum18468821994-06-20 07:49:28 +00001195 extra = ()
1196 if cnf.has_key('class'):
1197 extra = ('-class', cnf['class'])
1198 del cnf['class']
Guido van Rossum35f67fb1995-08-04 03:50:29 +00001199 Widget.__init__(self, master, 'frame', cnf, {}, extra)
Guido van Rossum18468821994-06-20 07:49:28 +00001200
1201class Label(Widget):
Guido van Rossum35f67fb1995-08-04 03:50:29 +00001202 def __init__(self, master=None, cnf={}, **kw):
1203 Widget.__init__(self, master, 'label', cnf, kw)
Guido van Rossum761c5ab1995-07-14 15:29:10 +00001204
Guido van Rossum18468821994-06-20 07:49:28 +00001205class Listbox(Widget):
Guido van Rossum35f67fb1995-08-04 03:50:29 +00001206 def __init__(self, master=None, cnf={}, **kw):
1207 Widget.__init__(self, master, 'listbox', cnf, kw)
Guido van Rossum46f92d21995-10-11 17:41:00 +00001208 def activate(self, index):
1209 self.tk.call(self._w, 'activate', index)
Guido van Rossum37dcab11996-05-16 16:00:19 +00001210 def bbox(self, *args):
1211 return self._getints(self._do('bbox', args)) or None
Guido van Rossum18468821994-06-20 07:49:28 +00001212 def curselection(self):
Guido van Rossum37dcab11996-05-16 16:00:19 +00001213 # XXX Ought to apply self._getints()...
Guido van Rossum18468821994-06-20 07:49:28 +00001214 return self.tk.splitlist(self.tk.call(
1215 self._w, 'curselection'))
1216 def delete(self, first, last=None):
1217 self.tk.call(self._w, 'delete', first, last)
Guido van Rossum37dcab11996-05-16 16:00:19 +00001218 def get(self, first, last=None):
1219 if last:
1220 return self.tk.splitlist(self.tk.call(
1221 self._w, 'get', first, last))
1222 else:
1223 return self.tk.call(self._w, 'get', first)
Guido van Rossum18468821994-06-20 07:49:28 +00001224 def insert(self, index, *elements):
1225 apply(self.tk.call,
1226 (self._w, 'insert', index) + elements)
1227 def nearest(self, y):
1228 return self.tk.getint(self.tk.call(
1229 self._w, 'nearest', y))
1230 def scan_mark(self, x, y):
1231 self.tk.call(self._w, 'scan', 'mark', x, y)
1232 def scan_dragto(self, x, y):
1233 self.tk.call(self._w, 'scan', 'dragto', x, y)
Guido van Rossum37dcab11996-05-16 16:00:19 +00001234 def see(self, index):
1235 self.tk.call(self._w, 'see', index)
1236 def index(self, index):
1237 i = self.tk.call(self._w, 'index', index)
1238 if i == 'none': return None
1239 return self.tk.getint(i)
Guido van Rossum18468821994-06-20 07:49:28 +00001240 def select_adjust(self, index):
1241 self.tk.call(self._w, 'select', 'adjust', index)
Guido van Rossum37dcab11996-05-16 16:00:19 +00001242 def select_anchor(self, index):
1243 self.tk.call(self._w, 'selection', 'anchor', index)
1244 def select_clear(self, first, last=None):
1245 self.tk.call(self._w,
1246 'selection', 'clear', first, last)
1247 def select_includes(self, index):
1248 return self.tk.getboolean(self.tk.call(
1249 self._w, 'selection', 'includes', index))
1250 def select_set(self, first, last=None):
1251 self.tk.call(self._w, 'selection', 'set', first, last)
Guido van Rossum18468821994-06-20 07:49:28 +00001252 def size(self):
1253 return self.tk.getint(self.tk.call(self._w, 'size'))
Guido van Rossum761c5ab1995-07-14 15:29:10 +00001254 def xview(self, *what):
Guido van Rossum37dcab11996-05-16 16:00:19 +00001255 if not what:
1256 return self._getdoubles(self.tk.call(self._w, 'xview'))
Guido van Rossum761c5ab1995-07-14 15:29:10 +00001257 apply(self.tk.call, (self._w, 'xview')+what)
1258 def yview(self, *what):
Guido van Rossum37dcab11996-05-16 16:00:19 +00001259 if not what:
1260 return self._getdoubles(self.tk.call(self._w, 'yview'))
Guido van Rossum761c5ab1995-07-14 15:29:10 +00001261 apply(self.tk.call, (self._w, 'yview')+what)
Guido van Rossum18468821994-06-20 07:49:28 +00001262
1263class Menu(Widget):
Guido van Rossum35f67fb1995-08-04 03:50:29 +00001264 def __init__(self, master=None, cnf={}, **kw):
1265 Widget.__init__(self, master, 'menu', cnf, kw)
Guido van Rossum18468821994-06-20 07:49:28 +00001266 def tk_bindForTraversal(self):
Guido van Rossum688bbfc1996-09-10 12:39:26 +00001267 pass # obsolete since Tk 4.0
Guido van Rossum18468821994-06-20 07:49:28 +00001268 def tk_mbPost(self):
1269 self.tk.call('tk_mbPost', self._w)
1270 def tk_mbUnpost(self):
1271 self.tk.call('tk_mbUnpost')
1272 def tk_traverseToMenu(self, char):
1273 self.tk.call('tk_traverseToMenu', self._w, char)
1274 def tk_traverseWithinMenu(self, char):
1275 self.tk.call('tk_traverseWithinMenu', self._w, char)
1276 def tk_getMenuButtons(self):
1277 return self.tk.call('tk_getMenuButtons', self._w)
1278 def tk_nextMenu(self, count):
1279 self.tk.call('tk_nextMenu', count)
1280 def tk_nextMenuEntry(self, count):
1281 self.tk.call('tk_nextMenuEntry', count)
1282 def tk_invokeMenu(self):
1283 self.tk.call('tk_invokeMenu', self._w)
1284 def tk_firstMenu(self):
1285 self.tk.call('tk_firstMenu', self._w)
1286 def tk_mbButtonDown(self):
1287 self.tk.call('tk_mbButtonDown', self._w)
Guido van Rossum37dcab11996-05-16 16:00:19 +00001288 def tk_popup(self, x, y, entry=""):
1289 self.tk.call('tk_popup', self._w, x, y, entry)
Guido van Rossum18468821994-06-20 07:49:28 +00001290 def activate(self, index):
1291 self.tk.call(self._w, 'activate', index)
Guido van Rossum35f67fb1995-08-04 03:50:29 +00001292 def add(self, itemType, cnf={}, **kw):
Guido van Rossum18468821994-06-20 07:49:28 +00001293 apply(self.tk.call, (self._w, 'add', itemType)
Guido van Rossum35f67fb1995-08-04 03:50:29 +00001294 + self._options(cnf, kw))
Guido van Rossuma1db48b1995-10-09 22:37:28 +00001295 def add_cascade(self, cnf={}, **kw):
1296 self.add('cascade', cnf or kw)
1297 def add_checkbutton(self, cnf={}, **kw):
1298 self.add('checkbutton', cnf or kw)
1299 def add_command(self, cnf={}, **kw):
1300 self.add('command', cnf or kw)
1301 def add_radiobutton(self, cnf={}, **kw):
1302 self.add('radiobutton', cnf or kw)
1303 def add_separator(self, cnf={}, **kw):
1304 self.add('separator', cnf or kw)
Guido van Rossum2caac731996-09-05 16:46:31 +00001305 def insert(self, index, itemType, cnf={}, **kw):
1306 apply(self.tk.call, (self._w, 'insert', index, itemType)
1307 + self._options(cnf, kw))
1308 def insert_cascade(self, index, cnf={}, **kw):
1309 self.insert(index, 'cascade', cnf or kw)
1310 def insert_checkbutton(self, index, cnf={}, **kw):
1311 self.insert(index, 'checkbutton', cnf or kw)
1312 def insert_command(self, index, cnf={}, **kw):
1313 self.insert(index, 'command', cnf or kw)
1314 def insert_radiobutton(self, index, cnf={}, **kw):
1315 self.insert(index, 'radiobutton', cnf or kw)
1316 def insert_separator(self, index, cnf={}, **kw):
1317 self.insert(index, 'separator', cnf or kw)
Guido van Rossum18468821994-06-20 07:49:28 +00001318 def delete(self, index1, index2=None):
1319 self.tk.call(self._w, 'delete', index1, index2)
Guido van Rossum37dcab11996-05-16 16:00:19 +00001320 def entryconfig(self, index, cnf=None, **kw):
1321 if cnf is None and not kw:
1322 cnf = {}
1323 for x in self.tk.split(apply(self.tk.call,
1324 (self._w, 'entryconfigure', index))):
1325 cnf[x[0][1:]] = (x[0][1:],) + x[1:]
1326 return cnf
1327 if type(cnf) == StringType and not kw:
1328 x = self.tk.split(apply(self.tk.call,
1329 (self._w, 'entryconfigure', index, '-'+cnf)))
1330 return (x[0][1:],) + x[1:]
Guido van Rossum18468821994-06-20 07:49:28 +00001331 apply(self.tk.call, (self._w, 'entryconfigure', index)
Guido van Rossum35f67fb1995-08-04 03:50:29 +00001332 + self._options(cnf, kw))
Guido van Rossum37dcab11996-05-16 16:00:19 +00001333 entryconfigure = entryconfig
Guido van Rossum18468821994-06-20 07:49:28 +00001334 def index(self, index):
Guido van Rossum535cf0c1994-06-27 07:55:59 +00001335 i = self.tk.call(self._w, 'index', index)
1336 if i == 'none': return None
1337 return self.tk.getint(i)
Guido van Rossum18468821994-06-20 07:49:28 +00001338 def invoke(self, index):
1339 return self.tk.call(self._w, 'invoke', index)
1340 def post(self, x, y):
1341 self.tk.call(self._w, 'post', x, y)
1342 def unpost(self):
1343 self.tk.call(self._w, 'unpost')
1344 def yposition(self, index):
1345 return self.tk.getint(self.tk.call(
1346 self._w, 'yposition', index))
1347
1348class Menubutton(Widget):
Guido van Rossum35f67fb1995-08-04 03:50:29 +00001349 def __init__(self, master=None, cnf={}, **kw):
1350 Widget.__init__(self, master, 'menubutton', cnf, kw)
Guido van Rossum18468821994-06-20 07:49:28 +00001351
1352class Message(Widget):
Guido van Rossum35f67fb1995-08-04 03:50:29 +00001353 def __init__(self, master=None, cnf={}, **kw):
1354 Widget.__init__(self, master, 'message', cnf, kw)
Guido van Rossum18468821994-06-20 07:49:28 +00001355
1356class Radiobutton(Widget):
Guido van Rossum35f67fb1995-08-04 03:50:29 +00001357 def __init__(self, master=None, cnf={}, **kw):
1358 Widget.__init__(self, master, 'radiobutton', cnf, kw)
Guido van Rossum18468821994-06-20 07:49:28 +00001359 def deselect(self):
1360 self.tk.call(self._w, 'deselect')
1361 def flash(self):
1362 self.tk.call(self._w, 'flash')
1363 def invoke(self):
1364 self.tk.call(self._w, 'invoke')
1365 def select(self):
1366 self.tk.call(self._w, 'select')
1367
1368class Scale(Widget):
Guido van Rossum35f67fb1995-08-04 03:50:29 +00001369 def __init__(self, master=None, cnf={}, **kw):
1370 Widget.__init__(self, master, 'scale', cnf, kw)
Guido van Rossum18468821994-06-20 07:49:28 +00001371 def get(self):
Guido van Rossum14957471996-10-23 14:16:28 +00001372 value = self.tk.call(self._w, 'get')
1373 try:
1374 return self.tk.getint(value)
1375 except TclError:
1376 return self.tk.getdouble(value)
Guido van Rossum18468821994-06-20 07:49:28 +00001377 def set(self, value):
1378 self.tk.call(self._w, 'set', value)
1379
1380class Scrollbar(Widget):
Guido van Rossum35f67fb1995-08-04 03:50:29 +00001381 def __init__(self, master=None, cnf={}, **kw):
1382 Widget.__init__(self, master, 'scrollbar', cnf, kw)
Guido van Rossum37dcab11996-05-16 16:00:19 +00001383 def activate(self, index):
1384 self.tk.call(self._w, 'activate', index)
1385 def delta(self, deltax, deltay):
1386 return self.getdouble(self.tk.call(
1387 self._w, 'delta', deltax, deltay))
1388 def fraction(self, x, y):
1389 return self.getdouble(self.tk.call(
1390 self._w, 'fraction', x, y))
1391 def identify(self, x, y):
1392 return self.tk.call(self._w, 'identify', x, y)
Guido van Rossum18468821994-06-20 07:49:28 +00001393 def get(self):
Guido van Rossum37dcab11996-05-16 16:00:19 +00001394 return self._getdoubles(self.tk.call(self._w, 'get'))
Guido van Rossum761c5ab1995-07-14 15:29:10 +00001395 def set(self, *args):
1396 apply(self.tk.call, (self._w, 'set')+args)
Guido van Rossum18468821994-06-20 07:49:28 +00001397
1398class Text(Widget):
Guido van Rossum35f67fb1995-08-04 03:50:29 +00001399 def __init__(self, master=None, cnf={}, **kw):
1400 Widget.__init__(self, master, 'text', cnf, kw)
Guido van Rossum37dcab11996-05-16 16:00:19 +00001401 def bbox(self, *args):
1402 return self._getints(self._do('bbox', args)) or None
Guido van Rossum18468821994-06-20 07:49:28 +00001403 def tk_textSelectTo(self, index):
1404 self.tk.call('tk_textSelectTo', self._w, index)
1405 def tk_textBackspace(self):
1406 self.tk.call('tk_textBackspace', self._w)
1407 def tk_textIndexCloser(self, a, b, c):
1408 self.tk.call('tk_textIndexCloser', self._w, a, b, c)
1409 def tk_textResetAnchor(self, index):
1410 self.tk.call('tk_textResetAnchor', self._w, index)
1411 def compare(self, index1, op, index2):
1412 return self.tk.getboolean(self.tk.call(
1413 self._w, 'compare', index1, op, index2))
1414 def debug(self, boolean=None):
1415 return self.tk.getboolean(self.tk.call(
1416 self._w, 'debug', boolean))
1417 def delete(self, index1, index2=None):
1418 self.tk.call(self._w, 'delete', index1, index2)
Guido van Rossum37dcab11996-05-16 16:00:19 +00001419 def dlineinfo(self, index):
1420 return self._getints(self.tk.call(self._w, 'dlineinfo', index))
Guido van Rossum18468821994-06-20 07:49:28 +00001421 def get(self, index1, index2=None):
1422 return self.tk.call(self._w, 'get', index1, index2)
1423 def index(self, index):
1424 return self.tk.call(self._w, 'index', index)
Guido van Rossum35f67fb1995-08-04 03:50:29 +00001425 def insert(self, index, chars, *args):
1426 apply(self.tk.call, (self._w, 'insert', index, chars)+args)
Guido van Rossum37dcab11996-05-16 16:00:19 +00001427 def mark_gravity(self, markName, direction=None):
1428 return apply(self.tk.call,
1429 (self._w, 'mark', 'gravity', markName, direction))
Guido van Rossum18468821994-06-20 07:49:28 +00001430 def mark_names(self):
1431 return self.tk.splitlist(self.tk.call(
1432 self._w, 'mark', 'names'))
1433 def mark_set(self, markName, index):
1434 self.tk.call(self._w, 'mark', 'set', markName, index)
Guido van Rossum37dcab11996-05-16 16:00:19 +00001435 def mark_unset(self, *markNames):
Guido van Rossum18468821994-06-20 07:49:28 +00001436 apply(self.tk.call, (self._w, 'mark', 'unset') + markNames)
Guido van Rossum37dcab11996-05-16 16:00:19 +00001437 def scan_mark(self, x, y):
1438 self.tk.call(self._w, 'scan', 'mark', x, y)
1439 def scan_dragto(self, x, y):
1440 self.tk.call(self._w, 'scan', 'dragto', x, y)
Guido van Rossum96ebbd31995-09-30 17:05:26 +00001441 def search(self, pattern, index, stopindex=None,
1442 forwards=None, backwards=None, exact=None,
1443 regexp=None, nocase=None, count=None):
Guido van Rossum37dcab11996-05-16 16:00:19 +00001444 args = [self._w, 'search']
1445 if forwards: args.append('-forwards')
1446 if backwards: args.append('-backwards')
1447 if exact: args.append('-exact')
1448 if regexp: args.append('-regexp')
1449 if nocase: args.append('-nocase')
1450 if count: args.append('-count'); args.append(count)
1451 if pattern[0] == '-': args.append('--')
1452 args.append(pattern)
1453 args.append(index)
1454 if stopindex: args.append(stopindex)
1455 return apply(self.tk.call, tuple(args))
1456 def see(self, index):
1457 self.tk.call(self._w, 'see', index)
Guido van Rossum18468821994-06-20 07:49:28 +00001458 def tag_add(self, tagName, index1, index2=None):
1459 self.tk.call(
1460 self._w, 'tag', 'add', tagName, index1, index2)
Guido van Rossumef8f8811994-08-08 12:47:33 +00001461 def tag_unbind(self, tagName, sequence):
1462 self.tk.call(self._w, 'tag', 'bind', tagName, sequence, '')
Guido van Rossum37dcab11996-05-16 16:00:19 +00001463 def tag_bind(self, tagName, sequence, func, add=None):
1464 return self._bind((self._w, 'tag', 'bind', tagName),
1465 sequence, func, add)
1466 def tag_cget(self, tagName, option):
Guido van Rossum73eba251996-11-11 19:10:58 +00001467 if option[:1] != '-':
1468 option = '-' + option
1469 if option[-1:] == '_':
1470 option = option[:-1]
Guido van Rossum37dcab11996-05-16 16:00:19 +00001471 return self.tk.call(self._w, 'tag', 'cget', tagName, option)
Guido van Rossum35f67fb1995-08-04 03:50:29 +00001472 def tag_config(self, tagName, cnf={}, **kw):
Guido van Rossum37dcab11996-05-16 16:00:19 +00001473 if type(cnf) == StringType:
1474 x = self.tk.split(self.tk.call(
1475 self._w, 'tag', 'configure', tagName, '-'+cnf))
1476 return (x[0][1:],) + x[1:]
Guido van Rossum18468821994-06-20 07:49:28 +00001477 apply(self.tk.call,
Guido van Rossum35f67fb1995-08-04 03:50:29 +00001478 (self._w, 'tag', 'configure', tagName)
1479 + self._options(cnf, kw))
Guido van Rossum37dcab11996-05-16 16:00:19 +00001480 tag_configure = tag_config
Guido van Rossum2dcf5291994-07-06 09:23:20 +00001481 def tag_delete(self, *tagNames):
Guido van Rossum2a390311994-07-06 10:20:11 +00001482 apply(self.tk.call, (self._w, 'tag', 'delete') + tagNames)
Guido van Rossum18468821994-06-20 07:49:28 +00001483 def tag_lower(self, tagName, belowThis=None):
Guido van Rossum97aeca11994-07-07 13:12:12 +00001484 self.tk.call(self._w, 'tag', 'lower', tagName, belowThis)
Guido van Rossum18468821994-06-20 07:49:28 +00001485 def tag_names(self, index=None):
1486 return self.tk.splitlist(
1487 self.tk.call(self._w, 'tag', 'names', index))
1488 def tag_nextrange(self, tagName, index1, index2=None):
1489 return self.tk.splitlist(self.tk.call(
Guido van Rossum903abee1995-03-20 15:09:13 +00001490 self._w, 'tag', 'nextrange', tagName, index1, index2))
Guido van Rossum18468821994-06-20 07:49:28 +00001491 def tag_raise(self, tagName, aboveThis=None):
1492 self.tk.call(
1493 self._w, 'tag', 'raise', tagName, aboveThis)
1494 def tag_ranges(self, tagName):
1495 return self.tk.splitlist(self.tk.call(
1496 self._w, 'tag', 'ranges', tagName))
1497 def tag_remove(self, tagName, index1, index2=None):
1498 self.tk.call(
Guido van Rossum51135691994-07-06 21:16:58 +00001499 self._w, 'tag', 'remove', tagName, index1, index2)
Guido van Rossum35f67fb1995-08-04 03:50:29 +00001500 def window_cget(self, index, option):
1501 return self.tk.call(self._w, 'window', 'cget', index, option)
1502 def window_config(self, index, cnf={}, **kw):
Guido van Rossum37dcab11996-05-16 16:00:19 +00001503 if type(cnf) == StringType:
1504 x = self.tk.split(self.tk.call(
1505 self._w, 'window', 'configure',
1506 index, '-'+cnf))
1507 return (x[0][1:],) + x[1:]
Guido van Rossum35f67fb1995-08-04 03:50:29 +00001508 apply(self.tk.call,
1509 (self._w, 'window', 'configure', index)
1510 + self._options(cnf, kw))
Guido van Rossum37dcab11996-05-16 16:00:19 +00001511 window_configure = window_config
Guido van Rossum35f67fb1995-08-04 03:50:29 +00001512 def window_create(self, index, cnf={}, **kw):
1513 apply(self.tk.call,
1514 (self._w, 'window', 'create', index)
1515 + self._options(cnf, kw))
1516 def window_names(self):
1517 return self.tk.splitlist(
1518 self.tk.call(self._w, 'window', 'names'))
Guido van Rossum37dcab11996-05-16 16:00:19 +00001519 def xview(self, *what):
1520 if not what:
1521 return self._getdoubles(self.tk.call(self._w, 'xview'))
1522 apply(self.tk.call, (self._w, 'xview')+what)
Guido van Rossum761c5ab1995-07-14 15:29:10 +00001523 def yview(self, *what):
Guido van Rossum37dcab11996-05-16 16:00:19 +00001524 if not what:
1525 return self._getdoubles(self.tk.call(self._w, 'yview'))
Guido van Rossum761c5ab1995-07-14 15:29:10 +00001526 apply(self.tk.call, (self._w, 'yview')+what)
1527 def yview_pickplace(self, *what):
1528 apply(self.tk.call, (self._w, 'yview', '-pickplace')+what)
Guido van Rossum18468821994-06-20 07:49:28 +00001529
Guido van Rossum28574b51996-10-21 15:16:51 +00001530class _setit:
1531 def __init__(self, var, value):
1532 self.__value = value
1533 self.__var = var
1534
1535 def __call__(self, *args):
Fred Drake0c373691996-10-21 17:09:31 +00001536 self.__var.set(self.__value)
Guido van Rossum28574b51996-10-21 15:16:51 +00001537
1538class OptionMenu(Menubutton):
Guido van Rossumbf4d8f91995-09-01 20:35:37 +00001539 def __init__(self, master, variable, value, *values):
Guido van Rossum28574b51996-10-21 15:16:51 +00001540 kw = {"borderwidth": 2, "textvariable": variable,
1541 "indicatoron": 1, "relief": RAISED, "anchor": "c",
1542 "highlightthickness": 2}
1543 Widget.__init__(self, master, "menubutton", kw)
Guido van Rossumbf4d8f91995-09-01 20:35:37 +00001544 self.widgetName = 'tk_optionMenu'
Guido van Rossum28574b51996-10-21 15:16:51 +00001545 menu = self.__menu = Menu(self, name="menu", tearoff=0)
1546 self.menuname = menu._w
1547 menu.add_command(label=value, command=_setit(variable, value))
1548 for v in values:
1549 menu.add_command(label=v, command=_setit(variable, v))
1550 self["menu"] = menu
1551
1552 def __getitem__(self, name):
1553 if name == 'menu':
1554 return self.__menu
1555 return Widget.__getitem__(self, name)
1556
1557 def destroy(self):
1558 Menubutton.destroy(self)
1559 self.__menu = None
Guido van Rossumbf4d8f91995-09-01 20:35:37 +00001560
Guido van Rossum35f67fb1995-08-04 03:50:29 +00001561class Image:
1562 def __init__(self, imgtype, name=None, cnf={}, **kw):
1563 self.name = None
1564 master = _default_root
1565 if not master: raise RuntimeError, 'Too early to create image'
1566 self.tk = master.tk
1567 if not name: name = `id(self)`
1568 if kw and cnf: cnf = _cnfmerge((cnf, kw))
1569 elif kw: cnf = kw
1570 options = ()
1571 for k, v in cnf.items():
Guido van Rossum37dcab11996-05-16 16:00:19 +00001572 if callable(v):
Guido van Rossum35f67fb1995-08-04 03:50:29 +00001573 v = self._register(v)
1574 options = options + ('-'+k, v)
1575 apply(self.tk.call,
1576 ('image', 'create', imgtype, name,) + options)
1577 self.name = name
1578 def __str__(self): return self.name
1579 def __del__(self):
1580 if self.name:
1581 self.tk.call('image', 'delete', self.name)
Guido van Rossum71b1a901995-09-18 21:54:35 +00001582 def __setitem__(self, key, value):
1583 self.tk.call(self.name, 'configure', '-'+key, value)
1584 def __getitem__(self, key):
1585 return self.tk.call(self.name, 'configure', '-'+key)
Guido van Rossum35f67fb1995-08-04 03:50:29 +00001586 def height(self):
1587 return self.tk.getint(
1588 self.tk.call('image', 'height', self.name))
1589 def type(self):
1590 return self.tk.call('image', 'type', self.name)
1591 def width(self):
1592 return self.tk.getint(
1593 self.tk.call('image', 'width', self.name))
1594
1595class PhotoImage(Image):
1596 def __init__(self, name=None, cnf={}, **kw):
1597 apply(Image.__init__, (self, 'photo', name, cnf), kw)
Guido van Rossum96ebbd31995-09-30 17:05:26 +00001598 def blank(self):
1599 self.tk.call(self.name, 'blank')
Guido van Rossum37dcab11996-05-16 16:00:19 +00001600 def cget(self, option):
1601 return self.tk.call(self.name, 'cget', '-' + option)
Guido van Rossum96ebbd31995-09-30 17:05:26 +00001602 # XXX config
Guido van Rossum37dcab11996-05-16 16:00:19 +00001603 def __getitem__(self, key):
1604 return self.tk.call(self.name, 'cget', '-' + key)
1605 def copy(self):
1606 destImage = PhotoImage()
1607 self.tk.call(destImage, 'copy', self.name)
1608 return destImage
1609 def zoom(self,x,y=''):
1610 destImage = PhotoImage()
1611 if y=='': y=x
1612 self.tk.call(destImage, 'copy', self.name, '-zoom',x,y)
1613 return destImage
1614 def subsample(self,x,y=''):
1615 destImage = PhotoImage()
1616 if y=='': y=x
1617 self.tk.call(destImage, 'copy', self.name, '-subsample',x,y)
1618 return destImage
Guido van Rossum96ebbd31995-09-30 17:05:26 +00001619 def get(self, x, y):
1620 return self.tk.call(self.name, 'get', x, y)
1621 def put(self, data, to=None):
1622 args = (self.name, 'put', data)
1623 if to:
1624 args = args + to
1625 apply(self.tk.call, args)
1626 # XXX read
Guido van Rossum37dcab11996-05-16 16:00:19 +00001627 def write(self, filename, format=None, from_coords=None):
1628 args = (self.name, 'write', filename)
1629 if format:
1630 args = args + ('-format', format)
1631 if from_coords:
1632 args = args + ('-from',) + tuple(from_coords)
1633 apply(self.tk.call, args)
Guido van Rossum35f67fb1995-08-04 03:50:29 +00001634
1635class BitmapImage(Image):
1636 def __init__(self, name=None, cnf={}, **kw):
1637 apply(Image.__init__, (self, 'bitmap', name, cnf), kw)
1638
1639def image_names(): return _default_root.tk.call('image', 'names')
1640def image_types(): return _default_root.tk.call('image', 'types')
1641
Guido van Rossumaec5dc91994-06-27 07:55:12 +00001642######################################################################
1643# Extensions:
1644
1645class Studbutton(Button):
Guido van Rossum35f67fb1995-08-04 03:50:29 +00001646 def __init__(self, master=None, cnf={}, **kw):
1647 Widget.__init__(self, master, 'studbutton', cnf, kw)
Guido van Rossum761c5ab1995-07-14 15:29:10 +00001648 self.bind('<Any-Enter>', self.tkButtonEnter)
1649 self.bind('<Any-Leave>', self.tkButtonLeave)
1650 self.bind('<1>', self.tkButtonDown)
1651 self.bind('<ButtonRelease-1>', self.tkButtonUp)
Guido van Rossumaec5dc91994-06-27 07:55:12 +00001652
1653class Tributton(Button):
Guido van Rossum35f67fb1995-08-04 03:50:29 +00001654 def __init__(self, master=None, cnf={}, **kw):
1655 Widget.__init__(self, master, 'tributton', cnf, kw)
Guido van Rossum761c5ab1995-07-14 15:29:10 +00001656 self.bind('<Any-Enter>', self.tkButtonEnter)
1657 self.bind('<Any-Leave>', self.tkButtonLeave)
1658 self.bind('<1>', self.tkButtonDown)
1659 self.bind('<ButtonRelease-1>', self.tkButtonUp)
1660 self['fg'] = self['bg']
1661 self['activebackground'] = self['bg']
Guido van Rossum37dcab11996-05-16 16:00:19 +00001662
Guido van Rossumc417ef81996-08-21 23:38:59 +00001663######################################################################
1664# Test:
1665
1666def _test():
1667 root = Tk()
1668 label = Label(root, text="Proof-of-existence test for Tk")
1669 label.pack()
1670 test = Button(root, text="Click me!",
1671 command=lambda root=root: root.test.config(
1672 text="[%s]" % root.test['text']))
1673 test.pack()
1674 root.test = test
1675 quit = Button(root, text="QUIT", command=root.destroy)
1676 quit.pack()
1677 root.mainloop()
1678
1679if __name__ == '__main__':
1680 _test()
1681
Guido van Rossum37dcab11996-05-16 16:00:19 +00001682
1683# Emacs cruft
1684# Local Variables:
1685# py-indent-offset: 8
1686# End: