Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1 | # Tkinter.py -- Tk/Tcl widget wrappers |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame] | 2 | |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 3 | __version__ = "$Revision$" |
| 4 | |
| 5 | try: |
| 6 | # See if modern _tkinter is present |
| 7 | import _tkinter |
| 8 | tkinter = _tkinter # b/w compat |
| 9 | except 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 |
| 22 | TclError = tkinter.TclError |
Guido van Rossum | 7e9394a | 1995-03-17 16:21:33 +0000 | [diff] [blame] | 23 | from types import * |
Guido van Rossum | a5773dd | 1995-09-07 19:22:00 +0000 | [diff] [blame] | 24 | from Tkconstants import * |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 25 | import string; _string = string; del string |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 26 | |
Guido van Rossum | 3626999 | 1996-05-16 17:11:27 +0000 | [diff] [blame] | 27 | TkVersion = _string.atof(tkinter.TK_VERSION) |
| 28 | TclVersion = _string.atof(tkinter.TCL_VERSION) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 29 | |
Guido van Rossum | 3626999 | 1996-05-16 17:11:27 +0000 | [diff] [blame] | 30 | ###################################################################### |
| 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 | ###################################################################### |
| 34 | if TkVersion >= 4.1: |
| 35 | READABLE = 2 |
| 36 | WRITABLE = 4 |
| 37 | EXCEPTION = 8 |
| 38 | else: |
| 39 | READABLE = 1 |
| 40 | WRITABLE = 2 |
| 41 | EXCEPTION = 4 |
| 42 | |
| 43 | |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame] | 44 | def _flatten(tuple): |
| 45 | res = () |
| 46 | for item in tuple: |
| 47 | if type(item) in (TupleType, ListType): |
| 48 | res = res + _flatten(item) |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 49 | elif item is not None: |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame] | 50 | res = res + (item,) |
| 51 | return res |
| 52 | |
| 53 | def _cnfmerge(cnfs): |
Guido van Rossum | 761c5ab | 1995-07-14 15:29:10 +0000 | [diff] [blame] | 54 | if type(cnfs) is DictionaryType: |
Guido van Rossum | 761c5ab | 1995-07-14 15:29:10 +0000 | [diff] [blame] | 55 | return cnfs |
| 56 | elif type(cnfs) in (NoneType, StringType): |
| 57 | |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame] | 58 | 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 | |
| 66 | class Event: |
| 67 | pass |
| 68 | |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 69 | _default_root = None |
| 70 | |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 71 | def _tkerror(err): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 72 | pass |
| 73 | |
Guido van Rossum | 97aeca1 | 1994-07-07 13:12:12 +0000 | [diff] [blame] | 74 | def _exit(code='0'): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 75 | raise SystemExit, code |
Guido van Rossum | 97aeca1 | 1994-07-07 13:12:12 +0000 | [diff] [blame] | 76 | |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 77 | _varnum = 0 |
| 78 | class Variable: |
| 79 | def __init__(self, master=None): |
| 80 | global _default_root |
| 81 | global _varnum |
| 82 | if master: |
| 83 | self._tk = master.tk |
| 84 | else: |
| 85 | self._tk = _default_root.tk |
| 86 | self._name = 'PY_VAR' + `_varnum` |
| 87 | _varnum = _varnum + 1 |
| 88 | def __del__(self): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 89 | self._tk.globalunsetvar(self._name) |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 90 | def __str__(self): |
| 91 | return self._name |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 92 | def set(self, value): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 93 | return self._tk.globalsetvar(self._name, value) |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 94 | |
| 95 | class StringVar(Variable): |
| 96 | def __init__(self, master=None): |
| 97 | Variable.__init__(self, master) |
| 98 | def get(self): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 99 | return self._tk.globalgetvar(self._name) |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 100 | |
| 101 | class IntVar(Variable): |
| 102 | def __init__(self, master=None): |
| 103 | Variable.__init__(self, master) |
| 104 | def get(self): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 105 | return self._tk.getint(self._tk.globalgetvar(self._name)) |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 106 | |
| 107 | class DoubleVar(Variable): |
| 108 | def __init__(self, master=None): |
| 109 | Variable.__init__(self, master) |
| 110 | def get(self): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 111 | return self._tk.getdouble(self._tk.globalgetvar(self._name)) |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 112 | |
| 113 | class BooleanVar(Variable): |
| 114 | def __init__(self, master=None): |
| 115 | Variable.__init__(self, master) |
| 116 | def get(self): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 117 | return self._tk.getboolean(self._tk.globalgetvar(self._name)) |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 118 | |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 119 | def mainloop(n=0): |
| 120 | _default_root.tk.mainloop(n) |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame] | 121 | |
| 122 | def getint(s): |
| 123 | return _default_root.tk.getint(s) |
| 124 | |
| 125 | def getdouble(s): |
| 126 | return _default_root.tk.getdouble(s) |
| 127 | |
| 128 | def getboolean(s): |
| 129 | return _default_root.tk.getboolean(s) |
| 130 | |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 131 | class Misc: |
| 132 | def tk_strictMotif(self, boolean=None): |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame] | 133 | return self.tk.getboolean(self.tk.call( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 134 | 'set', 'tk_strictMotif', boolean)) |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 135 | def tk_menuBar(self, *args): |
| 136 | apply(self.tk.call, ('tk_menuBar', self._w) + args) |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame] | 137 | def wait_variable(self, name='PY_VAR'): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 138 | self.tk.call('tkwait', 'variable', name) |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame] | 139 | waitvar = wait_variable # XXX b/w compat |
Guido van Rossum | 9beb932 | 1994-06-27 23:15:31 +0000 | [diff] [blame] | 140 | def wait_window(self, window=None): |
| 141 | if window == None: |
| 142 | window = self |
| 143 | self.tk.call('tkwait', 'window', window._w) |
| 144 | def wait_visibility(self, window=None): |
| 145 | if window == None: |
| 146 | window = self |
| 147 | self.tk.call('tkwait', 'visibility', window._w) |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 148 | def setvar(self, name='PY_VAR', value='1'): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 149 | self.tk.setvar(name, value) |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 150 | def getvar(self, name='PY_VAR'): |
Guido van Rossum | 5e8d372 | 1994-06-20 08:12:01 +0000 | [diff] [blame] | 151 | return self.tk.getvar(name) |
| 152 | def getint(self, s): |
| 153 | return self.tk.getint(s) |
Guido van Rossum | 1e9e400 | 1994-06-20 09:09:51 +0000 | [diff] [blame] | 154 | def getdouble(self, s): |
| 155 | return self.tk.getdouble(s) |
| 156 | def getboolean(self, s): |
| 157 | return self.tk.getboolean(s) |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 158 | def focus_set(self): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 159 | self.tk.call('focus', self._w) |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 160 | focus = focus_set # XXX b/w compat? |
| 161 | def focus_default_set(self): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 162 | self.tk.call('focus', 'default', self._w) |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 163 | def focus_default_none(self): |
| 164 | self.tk.call('focus', 'default', 'none') |
| 165 | focus_default = focus_default_set |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 166 | def focus_none(self): |
| 167 | self.tk.call('focus', 'none') |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 168 | def focus_get(self): |
| 169 | name = self.tk.call('focus') |
Guido van Rossum | 5468a7b | 1996-08-08 18:31:42 +0000 | [diff] [blame] | 170 | if name == 'none' or not name: return None |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 171 | return self._nametowidget(name) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 172 | def tk_focusNext(self): |
| 173 | name = self.tk.call('tk_focusNext', self._w) |
| 174 | if not name: return None |
| 175 | return self._nametowidget(name) |
| 176 | def tk_focusPrev(self): |
| 177 | name = self.tk.call('tk_focusPrev', self._w) |
| 178 | if not name: return None |
| 179 | return self._nametowidget(name) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 180 | def after(self, ms, func=None, *args): |
| 181 | if not func: |
Guido van Rossum | 96ebbd3 | 1995-09-30 17:05:26 +0000 | [diff] [blame] | 182 | # I'd rather use time.sleep(ms*0.001) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 183 | self.tk.call('after', ms) |
| 184 | else: |
Guido van Rossum | 08a4038 | 1994-06-21 11:44:21 +0000 | [diff] [blame] | 185 | # XXX Disgusting hack to clean up after calling func |
| 186 | tmp = [] |
| 187 | def callit(func=func, args=args, tk=self.tk, tmp=tmp): |
| 188 | try: |
| 189 | apply(func, args) |
| 190 | finally: |
| 191 | tk.deletecommand(tmp[0]) |
| 192 | name = self._register(callit) |
| 193 | tmp.append(name) |
Guido van Rossum | 96ebbd3 | 1995-09-30 17:05:26 +0000 | [diff] [blame] | 194 | return self.tk.call('after', ms, name) |
| 195 | def after_idle(self, func, *args): |
| 196 | return apply(self.after, ('idle', func) + args) |
| 197 | def after_cancel(self, id): |
| 198 | self.tk.call('after', 'cancel', id) |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 199 | def bell(self, displayof=None): |
| 200 | if displayof: |
| 201 | self.tk.call('bell', '-displayof', displayof) |
| 202 | else: |
| 203 | self.tk.call('bell', '-displayof', self._w) |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 204 | # XXX grab current w/o window argument |
| 205 | def grab_current(self): |
| 206 | name = self.tk.call('grab', 'current', self._w) |
| 207 | if not name: return None |
| 208 | return self._nametowidget(name) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 209 | def grab_release(self): |
| 210 | self.tk.call('grab', 'release', self._w) |
| 211 | def grab_set(self): |
| 212 | self.tk.call('grab', 'set', self._w) |
| 213 | def grab_set_global(self): |
| 214 | self.tk.call('grab', 'set', '-global', self._w) |
| 215 | def grab_status(self): |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 216 | status = self.tk.call('grab', 'status', self._w) |
| 217 | if status == 'none': status = None |
| 218 | return status |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 219 | def lower(self, belowThis=None): |
| 220 | self.tk.call('lower', self._w, belowThis) |
Guido van Rossum | 780044f | 1994-10-20 22:02:27 +0000 | [diff] [blame] | 221 | def option_add(self, pattern, value, priority = None): |
Guido van Rossum | 96ebbd3 | 1995-09-30 17:05:26 +0000 | [diff] [blame] | 222 | self.tk.call('option', 'add', pattern, value, priority) |
Guido van Rossum | 780044f | 1994-10-20 22:02:27 +0000 | [diff] [blame] | 223 | def option_clear(self): |
| 224 | self.tk.call('option', 'clear') |
| 225 | def option_get(self, name, className): |
| 226 | return self.tk.call('option', 'get', self._w, name, className) |
| 227 | def option_readfile(self, fileName, priority = None): |
| 228 | self.tk.call('option', 'readfile', fileName, priority) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 229 | def selection_clear(self): |
| 230 | self.tk.call('selection', 'clear', self._w) |
| 231 | def selection_get(self, type=None): |
Guido van Rossum | bd84b04 | 1994-07-04 10:48:25 +0000 | [diff] [blame] | 232 | return self.tk.call('selection', 'get', type) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 233 | def selection_handle(self, func, type=None, format=None): |
| 234 | name = self._register(func) |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 235 | self.tk.call('selection', 'handle', self._w, |
| 236 | name, type, format) |
| 237 | def selection_own(self, func=None): |
| 238 | name = self._register(func) |
| 239 | self.tk.call('selection', 'own', self._w, name) |
| 240 | def selection_own_get(self): |
| 241 | return self._nametowidget(self.tk.call('selection', 'own')) |
| 242 | def send(self, interp, cmd, *args): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 243 | return apply(self.tk.call, ('send', interp, cmd) + args) |
Guido van Rossum | 5e8d372 | 1994-06-20 08:12:01 +0000 | [diff] [blame] | 244 | def lower(self, belowThis=None): |
| 245 | self.tk.call('lift', self._w, belowThis) |
| 246 | def tkraise(self, aboveThis=None): |
| 247 | self.tk.call('raise', self._w, aboveThis) |
| 248 | lift = tkraise |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 249 | def colormodel(self, value=None): |
| 250 | return self.tk.call('tk', 'colormodel', self._w, value) |
| 251 | def winfo_atom(self, name): |
| 252 | return self.tk.getint(self.tk.call('winfo', 'atom', name)) |
| 253 | def winfo_atomname(self, id): |
| 254 | return self.tk.call('winfo', 'atomname', id) |
| 255 | def winfo_cells(self): |
| 256 | return self.tk.getint( |
| 257 | self.tk.call('winfo', 'cells', self._w)) |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 258 | def winfo_children(self): |
| 259 | return map(self._nametowidget, |
| 260 | self.tk.splitlist(self.tk.call( |
| 261 | 'winfo', 'children', self._w))) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 262 | def winfo_class(self): |
| 263 | return self.tk.call('winfo', 'class', self._w) |
| 264 | def winfo_containing(self, rootX, rootY): |
Guido van Rossum | 3626999 | 1996-05-16 17:11:27 +0000 | [diff] [blame] | 265 | return self.tk.call('winfo', 'containing', rootX, rootY) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 266 | def winfo_depth(self): |
| 267 | return self.tk.getint(self.tk.call('winfo', 'depth', self._w)) |
| 268 | def winfo_exists(self): |
| 269 | return self.tk.getint( |
| 270 | self.tk.call('winfo', 'exists', self._w)) |
| 271 | def winfo_fpixels(self, number): |
| 272 | return self.tk.getdouble(self.tk.call( |
| 273 | 'winfo', 'fpixels', self._w, number)) |
| 274 | def winfo_geometry(self): |
| 275 | return self.tk.call('winfo', 'geometry', self._w) |
| 276 | def winfo_height(self): |
| 277 | return self.tk.getint( |
| 278 | self.tk.call('winfo', 'height', self._w)) |
| 279 | def winfo_id(self): |
| 280 | return self.tk.getint( |
| 281 | self.tk.call('winfo', 'id', self._w)) |
| 282 | def winfo_interps(self): |
| 283 | return self.tk.splitlist( |
| 284 | self.tk.call('winfo', 'interps')) |
| 285 | def winfo_ismapped(self): |
| 286 | return self.tk.getint( |
| 287 | self.tk.call('winfo', 'ismapped', self._w)) |
| 288 | def winfo_name(self): |
| 289 | return self.tk.call('winfo', 'name', self._w) |
| 290 | def winfo_parent(self): |
| 291 | return self.tk.call('winfo', 'parent', self._w) |
| 292 | def winfo_pathname(self, id): |
| 293 | return self.tk.call('winfo', 'pathname', id) |
| 294 | def winfo_pixels(self, number): |
| 295 | return self.tk.getint( |
| 296 | self.tk.call('winfo', 'pixels', self._w, number)) |
| 297 | def winfo_reqheight(self): |
| 298 | return self.tk.getint( |
| 299 | self.tk.call('winfo', 'reqheight', self._w)) |
| 300 | def winfo_reqwidth(self): |
| 301 | return self.tk.getint( |
| 302 | self.tk.call('winfo', 'reqwidth', self._w)) |
| 303 | def winfo_rgb(self, color): |
| 304 | return self._getints( |
| 305 | self.tk.call('winfo', 'rgb', self._w, color)) |
| 306 | def winfo_rootx(self): |
| 307 | return self.tk.getint( |
| 308 | self.tk.call('winfo', 'rootx', self._w)) |
| 309 | def winfo_rooty(self): |
| 310 | return self.tk.getint( |
| 311 | self.tk.call('winfo', 'rooty', self._w)) |
| 312 | def winfo_screen(self): |
| 313 | return self.tk.call('winfo', 'screen', self._w) |
| 314 | def winfo_screencells(self): |
| 315 | return self.tk.getint( |
| 316 | self.tk.call('winfo', 'screencells', self._w)) |
| 317 | def winfo_screendepth(self): |
| 318 | return self.tk.getint( |
| 319 | self.tk.call('winfo', 'screendepth', self._w)) |
| 320 | def winfo_screenheight(self): |
| 321 | return self.tk.getint( |
| 322 | self.tk.call('winfo', 'screenheight', self._w)) |
| 323 | def winfo_screenmmheight(self): |
| 324 | return self.tk.getint( |
| 325 | self.tk.call('winfo', 'screenmmheight', self._w)) |
| 326 | def winfo_screenmmwidth(self): |
| 327 | return self.tk.getint( |
| 328 | self.tk.call('winfo', 'screenmmwidth', self._w)) |
| 329 | def winfo_screenvisual(self): |
| 330 | return self.tk.call('winfo', 'screenvisual', self._w) |
| 331 | def winfo_screenwidth(self): |
| 332 | return self.tk.getint( |
| 333 | self.tk.call('winfo', 'screenwidth', self._w)) |
| 334 | def winfo_toplevel(self): |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 335 | return self._nametowidget(self.tk.call( |
| 336 | 'winfo', 'toplevel', self._w)) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 337 | def winfo_visual(self): |
| 338 | return self.tk.call('winfo', 'visual', self._w) |
| 339 | def winfo_vrootheight(self): |
| 340 | return self.tk.getint( |
| 341 | self.tk.call('winfo', 'vrootheight', self._w)) |
| 342 | def winfo_vrootwidth(self): |
| 343 | return self.tk.getint( |
| 344 | self.tk.call('winfo', 'vrootwidth', self._w)) |
| 345 | def winfo_vrootx(self): |
| 346 | return self.tk.getint( |
| 347 | self.tk.call('winfo', 'vrootx', self._w)) |
| 348 | def winfo_vrooty(self): |
| 349 | return self.tk.getint( |
| 350 | self.tk.call('winfo', 'vrooty', self._w)) |
| 351 | def winfo_width(self): |
| 352 | return self.tk.getint( |
| 353 | self.tk.call('winfo', 'width', self._w)) |
| 354 | def winfo_x(self): |
| 355 | return self.tk.getint( |
| 356 | self.tk.call('winfo', 'x', self._w)) |
| 357 | def winfo_y(self): |
| 358 | return self.tk.getint( |
| 359 | self.tk.call('winfo', 'y', self._w)) |
| 360 | def update(self): |
| 361 | self.tk.call('update') |
| 362 | def update_idletasks(self): |
| 363 | self.tk.call('update', 'idletasks') |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 364 | def bindtags(self, tagList=None): |
| 365 | if tagList is None: |
| 366 | return self.tk.splitlist( |
| 367 | self.tk.call('bindtags', self._w)) |
Guido van Rossum | 761c5ab | 1995-07-14 15:29:10 +0000 | [diff] [blame] | 368 | else: |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 369 | self.tk.call('bindtags', self._w, tagList) |
| 370 | def _bind(self, what, sequence, func, add): |
| 371 | if func: |
| 372 | cmd = ("%sset _tkinter_break [%s %s]\n" |
| 373 | 'if {"$_tkinter_break" == "break"} break\n') \ |
| 374 | % (add and '+' or '', |
| 375 | self._register(func, self._substitute), |
| 376 | _string.join(self._subst_format)) |
| 377 | apply(self.tk.call, what + (sequence, cmd)) |
| 378 | elif func == '': |
| 379 | apply(self.tk.call, what + (sequence, func)) |
| 380 | else: |
| 381 | return apply(self.tk.call, what + (sequence,)) |
| 382 | def bind(self, sequence=None, func=None, add=None): |
| 383 | return self._bind(('bind', self._w), sequence, func, add) |
Guido van Rossum | ef8f881 | 1994-08-08 12:47:33 +0000 | [diff] [blame] | 384 | def unbind(self, sequence): |
| 385 | self.tk.call('bind', self._w, sequence, '') |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 386 | def bind_all(self, sequence=None, func=None, add=None): |
| 387 | return self._bind(('bind', 'all'), sequence, func, add) |
Guido van Rossum | 761c5ab | 1995-07-14 15:29:10 +0000 | [diff] [blame] | 388 | def unbind_all(self, sequence): |
| 389 | self.tk.call('bind', 'all' , sequence, '') |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 390 | def bind_class(self, className, sequence=None, func=None, add=None): |
| 391 | self._bind(('bind', className), sequence, func, add) |
Guido van Rossum | 761c5ab | 1995-07-14 15:29:10 +0000 | [diff] [blame] | 392 | def unbind_class(self, className, sequence): |
| 393 | self.tk.call('bind', className , sequence, '') |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 394 | def mainloop(self, n=0): |
| 395 | self.tk.mainloop(n) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 396 | def quit(self): |
| 397 | self.tk.quit() |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 398 | def _getints(self, string): |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 399 | if not string: return None |
Guido van Rossum | 7e9394a | 1995-03-17 16:21:33 +0000 | [diff] [blame] | 400 | return tuple(map(self.tk.getint, self.tk.splitlist(string))) |
| 401 | def _getdoubles(self, string): |
| 402 | if not string: return None |
| 403 | return tuple(map(self.tk.getdouble, self.tk.splitlist(string))) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 404 | def _getboolean(self, string): |
| 405 | if string: |
| 406 | return self.tk.getboolean(string) |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 407 | def _options(self, cnf, kw = None): |
| 408 | if kw: |
| 409 | cnf = _cnfmerge((cnf, kw)) |
| 410 | else: |
| 411 | cnf = _cnfmerge(cnf) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 412 | res = () |
| 413 | for k, v in cnf.items(): |
Guido van Rossum | a5773dd | 1995-09-07 19:22:00 +0000 | [diff] [blame] | 414 | if k[-1] == '_': k = k[:-1] |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 415 | if callable(v): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 416 | v = self._register(v) |
| 417 | res = res + ('-'+k, v) |
| 418 | return res |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 419 | def _nametowidget(self, name): |
| 420 | w = self |
| 421 | if name[0] == '.': |
| 422 | w = w._root() |
| 423 | name = name[1:] |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 424 | find = _string.find |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 425 | while name: |
| 426 | i = find(name, '.') |
| 427 | if i >= 0: |
| 428 | name, tail = name[:i], name[i+1:] |
| 429 | else: |
| 430 | tail = '' |
| 431 | w = w.children[name] |
| 432 | name = tail |
| 433 | return w |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 434 | def _register(self, func, subst=None): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 435 | f = CallWrapper(func, subst, self).__call__ |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 436 | name = `id(f)` |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 437 | try: |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 438 | func = func.im_func |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 439 | except AttributeError: |
| 440 | pass |
| 441 | try: |
Guido van Rossum | a5773dd | 1995-09-07 19:22:00 +0000 | [diff] [blame] | 442 | name = name + func.__name__ |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 443 | except AttributeError: |
| 444 | pass |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 445 | self.tk.createcommand(name, f) |
| 446 | return name |
Guido van Rossum | 9beb932 | 1994-06-27 23:15:31 +0000 | [diff] [blame] | 447 | register = _register |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 448 | def _root(self): |
| 449 | w = self |
| 450 | while w.master: w = w.master |
| 451 | return w |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 452 | _subst_format = ('%#', '%b', '%f', '%h', '%k', |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 453 | '%s', '%t', '%w', '%x', '%y', |
| 454 | '%A', '%E', '%K', '%N', '%W', '%T', '%X', '%Y') |
| 455 | def _substitute(self, *args): |
| 456 | tk = self.tk |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 457 | if len(args) != len(self._subst_format): return args |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 458 | nsign, b, f, h, k, s, t, w, x, y, A, E, K, N, W, T, X, Y = args |
| 459 | # Missing: (a, c, d, m, o, v, B, R) |
| 460 | e = Event() |
| 461 | e.serial = tk.getint(nsign) |
| 462 | e.num = tk.getint(b) |
| 463 | try: e.focus = tk.getboolean(f) |
| 464 | except TclError: pass |
| 465 | e.height = tk.getint(h) |
| 466 | e.keycode = tk.getint(k) |
Guido van Rossum | 3626999 | 1996-05-16 17:11:27 +0000 | [diff] [blame] | 467 | # For Visibility events, event state is a string and |
| 468 | # not an integer: |
| 469 | try: |
| 470 | e.state = tk.getint(s) |
| 471 | except TclError: |
| 472 | e.state = s |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 473 | e.time = tk.getint(t) |
| 474 | e.width = tk.getint(w) |
| 475 | e.x = tk.getint(x) |
| 476 | e.y = tk.getint(y) |
| 477 | e.char = A |
| 478 | try: e.send_event = tk.getboolean(E) |
| 479 | except TclError: pass |
| 480 | e.keysym = K |
| 481 | e.keysym_num = tk.getint(N) |
| 482 | e.type = T |
| 483 | e.widget = self._nametowidget(W) |
| 484 | e.x_root = tk.getint(X) |
| 485 | e.y_root = tk.getint(Y) |
| 486 | return (e,) |
Guido van Rossum | a5773dd | 1995-09-07 19:22:00 +0000 | [diff] [blame] | 487 | def _report_exception(self): |
| 488 | import sys |
| 489 | exc, val, tb = sys.exc_type, sys.exc_value, sys.exc_traceback |
| 490 | root = self._root() |
| 491 | root.report_callback_exception(exc, val, tb) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 492 | |
Guido van Rossum | a5773dd | 1995-09-07 19:22:00 +0000 | [diff] [blame] | 493 | class CallWrapper: |
| 494 | def __init__(self, func, subst, widget): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 495 | self.func = func |
| 496 | self.subst = subst |
Guido van Rossum | a5773dd | 1995-09-07 19:22:00 +0000 | [diff] [blame] | 497 | self.widget = widget |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 498 | def __call__(self, *args): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 499 | try: |
Guido van Rossum | a5773dd | 1995-09-07 19:22:00 +0000 | [diff] [blame] | 500 | if self.subst: |
| 501 | args = apply(self.subst, args) |
| 502 | return apply(self.func, args) |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 503 | except SystemExit, msg: |
| 504 | raise SystemExit, msg |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 505 | except: |
Guido van Rossum | a5773dd | 1995-09-07 19:22:00 +0000 | [diff] [blame] | 506 | self.widget._report_exception() |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 507 | |
| 508 | class Wm: |
| 509 | def aspect(self, |
| 510 | minNumer=None, minDenom=None, |
| 511 | maxNumer=None, maxDenom=None): |
| 512 | return self._getints( |
| 513 | self.tk.call('wm', 'aspect', self._w, |
| 514 | minNumer, minDenom, |
| 515 | maxNumer, maxDenom)) |
| 516 | def client(self, name=None): |
| 517 | return self.tk.call('wm', 'client', self._w, name) |
| 518 | def command(self, value=None): |
| 519 | return self.tk.call('wm', 'command', self._w, value) |
| 520 | def deiconify(self): |
| 521 | return self.tk.call('wm', 'deiconify', self._w) |
| 522 | def focusmodel(self, model=None): |
| 523 | return self.tk.call('wm', 'focusmodel', self._w, model) |
| 524 | def frame(self): |
| 525 | return self.tk.call('wm', 'frame', self._w) |
| 526 | def geometry(self, newGeometry=None): |
| 527 | return self.tk.call('wm', 'geometry', self._w, newGeometry) |
| 528 | def grid(self, |
| 529 | baseWidht=None, baseHeight=None, |
| 530 | widthInc=None, heightInc=None): |
| 531 | return self._getints(self.tk.call( |
| 532 | 'wm', 'grid', self._w, |
| 533 | baseWidht, baseHeight, widthInc, heightInc)) |
| 534 | def group(self, pathName=None): |
| 535 | return self.tk.call('wm', 'group', self._w, pathName) |
| 536 | def iconbitmap(self, bitmap=None): |
| 537 | return self.tk.call('wm', 'iconbitmap', self._w, bitmap) |
| 538 | def iconify(self): |
| 539 | return self.tk.call('wm', 'iconify', self._w) |
| 540 | def iconmask(self, bitmap=None): |
| 541 | return self.tk.call('wm', 'iconmask', self._w, bitmap) |
| 542 | def iconname(self, newName=None): |
| 543 | return self.tk.call('wm', 'iconname', self._w, newName) |
| 544 | def iconposition(self, x=None, y=None): |
| 545 | return self._getints(self.tk.call( |
| 546 | 'wm', 'iconposition', self._w, x, y)) |
| 547 | def iconwindow(self, pathName=None): |
| 548 | return self.tk.call('wm', 'iconwindow', self._w, pathName) |
| 549 | def maxsize(self, width=None, height=None): |
| 550 | return self._getints(self.tk.call( |
| 551 | 'wm', 'maxsize', self._w, width, height)) |
| 552 | def minsize(self, width=None, height=None): |
| 553 | return self._getints(self.tk.call( |
| 554 | 'wm', 'minsize', self._w, width, height)) |
| 555 | def overrideredirect(self, boolean=None): |
| 556 | return self._getboolean(self.tk.call( |
| 557 | 'wm', 'overrideredirect', self._w, boolean)) |
| 558 | def positionfrom(self, who=None): |
| 559 | return self.tk.call('wm', 'positionfrom', self._w, who) |
| 560 | def protocol(self, name=None, func=None): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 561 | if callable(func): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 562 | command = self._register(func) |
| 563 | else: |
| 564 | command = func |
| 565 | return self.tk.call( |
| 566 | 'wm', 'protocol', self._w, name, command) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 567 | def resizable(self, width=None, height=None): |
| 568 | return self.tk.call('wm', 'resizable', self._w, width, height) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 569 | def sizefrom(self, who=None): |
| 570 | return self.tk.call('wm', 'sizefrom', self._w, who) |
| 571 | def state(self): |
| 572 | return self.tk.call('wm', 'state', self._w) |
| 573 | def title(self, string=None): |
| 574 | return self.tk.call('wm', 'title', self._w, string) |
| 575 | def transient(self, master=None): |
| 576 | return self.tk.call('wm', 'transient', self._w, master) |
| 577 | def withdraw(self): |
| 578 | return self.tk.call('wm', 'withdraw', self._w) |
| 579 | |
| 580 | class Tk(Misc, Wm): |
| 581 | _w = '.' |
| 582 | def __init__(self, screenName=None, baseName=None, className='Tk'): |
Guido van Rossum | a5773dd | 1995-09-07 19:22:00 +0000 | [diff] [blame] | 583 | global _default_root |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 584 | self.master = None |
| 585 | self.children = {} |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 586 | if baseName is None: |
| 587 | import sys, os |
| 588 | baseName = os.path.basename(sys.argv[0]) |
| 589 | if baseName[-3:] == '.py': baseName = baseName[:-3] |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 590 | self.tk = tkinter.create(screenName, baseName, className) |
| 591 | try: |
| 592 | # Disable event scanning except for Command-Period |
| 593 | import MacOS |
| 594 | MacOS.EnableAppswitch(0) |
| 595 | except ImportError: |
| 596 | pass |
| 597 | else: |
| 598 | # Work around nasty MacTk bug |
| 599 | self.update() |
Guido van Rossum | f7f79ac | 1995-10-07 19:08:37 +0000 | [diff] [blame] | 600 | # Version sanity checks |
| 601 | tk_version = self.tk.getvar('tk_version') |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 602 | if tk_version != tkinter.TK_VERSION: |
Guido van Rossum | f7f79ac | 1995-10-07 19:08:37 +0000 | [diff] [blame] | 603 | raise RuntimeError, \ |
| 604 | "tk.h version (%s) doesn't match libtk.a version (%s)" \ |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 605 | % (tkinter.TK_VERSION, tk_version) |
Guido van Rossum | f7f79ac | 1995-10-07 19:08:37 +0000 | [diff] [blame] | 606 | tcl_version = self.tk.getvar('tcl_version') |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 607 | if tcl_version != tkinter.TCL_VERSION: |
Guido van Rossum | f7f79ac | 1995-10-07 19:08:37 +0000 | [diff] [blame] | 608 | raise RuntimeError, \ |
| 609 | "tcl.h version (%s) doesn't match libtcl.a version (%s)" \ |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 610 | % (tkinter.TCL_VERSION, tcl_version) |
Guido van Rossum | f7f79ac | 1995-10-07 19:08:37 +0000 | [diff] [blame] | 611 | if TkVersion < 4.0: |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 612 | raise RuntimeError, \ |
| 613 | "Tk 4.0 or higher is required; found Tk %s" \ |
| 614 | % str(TkVersion) |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 615 | self.tk.createcommand('tkerror', _tkerror) |
Guido van Rossum | 97aeca1 | 1994-07-07 13:12:12 +0000 | [diff] [blame] | 616 | self.tk.createcommand('exit', _exit) |
Guido van Rossum | 27b77a4 | 1994-07-12 15:52:32 +0000 | [diff] [blame] | 617 | self.readprofile(baseName, className) |
Guido van Rossum | a5773dd | 1995-09-07 19:22:00 +0000 | [diff] [blame] | 618 | if not _default_root: |
| 619 | _default_root = self |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 620 | def destroy(self): |
| 621 | for c in self.children.values(): c.destroy() |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 622 | self.tk.call('destroy', self._w) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 623 | def __str__(self): |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 624 | return self._w |
Guido van Rossum | 27b77a4 | 1994-07-12 15:52:32 +0000 | [diff] [blame] | 625 | def readprofile(self, baseName, className): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 626 | import os |
Guido van Rossum | 27b77a4 | 1994-07-12 15:52:32 +0000 | [diff] [blame] | 627 | if os.environ.has_key('HOME'): home = os.environ['HOME'] |
| 628 | else: home = os.curdir |
| 629 | class_tcl = os.path.join(home, '.%s.tcl' % className) |
| 630 | class_py = os.path.join(home, '.%s.py' % className) |
| 631 | base_tcl = os.path.join(home, '.%s.tcl' % baseName) |
| 632 | base_py = os.path.join(home, '.%s.py' % baseName) |
| 633 | dir = {'self': self} |
| 634 | exec 'from Tkinter import *' in dir |
| 635 | if os.path.isfile(class_tcl): |
| 636 | print 'source', `class_tcl` |
| 637 | self.tk.call('source', class_tcl) |
| 638 | if os.path.isfile(class_py): |
| 639 | print 'execfile', `class_py` |
| 640 | execfile(class_py, dir) |
| 641 | if os.path.isfile(base_tcl): |
| 642 | print 'source', `base_tcl` |
| 643 | self.tk.call('source', base_tcl) |
| 644 | if os.path.isfile(base_py): |
| 645 | print 'execfile', `base_py` |
| 646 | execfile(base_py, dir) |
Guido van Rossum | a5773dd | 1995-09-07 19:22:00 +0000 | [diff] [blame] | 647 | def report_callback_exception(self, exc, val, tb): |
| 648 | import traceback |
| 649 | print "Exception in Tkinter callback" |
| 650 | traceback.print_exception(exc, val, tb) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 651 | |
| 652 | class Pack: |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 653 | def config(self, cnf={}, **kw): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 654 | apply(self.tk.call, |
| 655 | ('pack', 'configure', self._w) |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 656 | + self._options(cnf, kw)) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 657 | configure = config |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 658 | pack = config |
| 659 | def __setitem__(self, key, value): |
| 660 | Pack.config({key: value}) |
| 661 | def forget(self): |
| 662 | self.tk.call('pack', 'forget', self._w) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 663 | pack_forget = forget |
| 664 | def info(self): |
Guido van Rossum | 69170c5 | 1994-07-11 15:21:31 +0000 | [diff] [blame] | 665 | words = self.tk.splitlist( |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 666 | self.tk.call('pack', 'info', self._w)) |
Guido van Rossum | 69170c5 | 1994-07-11 15:21:31 +0000 | [diff] [blame] | 667 | dict = {} |
| 668 | for i in range(0, len(words), 2): |
| 669 | key = words[i][1:] |
| 670 | value = words[i+1] |
Guido van Rossum | a5f875f | 1996-05-16 17:50:07 +0000 | [diff] [blame] | 671 | if value[:1] == '.': |
Guido van Rossum | 69170c5 | 1994-07-11 15:21:31 +0000 | [diff] [blame] | 672 | value = self._nametowidget(value) |
| 673 | dict[key] = value |
| 674 | return dict |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 675 | pack_info = info |
Guido van Rossum | 5505d56 | 1994-12-30 17:16:35 +0000 | [diff] [blame] | 676 | _noarg_ = ['_noarg_'] |
| 677 | def propagate(self, flag=_noarg_): |
Guido van Rossum | a5773dd | 1995-09-07 19:22:00 +0000 | [diff] [blame] | 678 | if flag is Pack._noarg_: |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 679 | return self._getboolean(self.tk.call( |
| 680 | 'pack', 'propagate', self._w)) |
Guido van Rossum | 5505d56 | 1994-12-30 17:16:35 +0000 | [diff] [blame] | 681 | else: |
| 682 | self.tk.call('pack', 'propagate', self._w, flag) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 683 | pack_propagate = propagate |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 684 | def slaves(self): |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 685 | return map(self._nametowidget, |
| 686 | self.tk.splitlist( |
| 687 | self.tk.call('pack', 'slaves', self._w))) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 688 | pack_slaves = slaves |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 689 | |
| 690 | class Place: |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 691 | def config(self, cnf={}, **kw): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 692 | for k in ['in_']: |
| 693 | if kw.has_key(k): |
| 694 | kw[k[:-1]] = kw[k] |
| 695 | del kw[k] |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 696 | apply(self.tk.call, |
| 697 | ('place', 'configure', self._w) |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 698 | + self._options(cnf, kw)) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 699 | configure = config |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 700 | place = config |
| 701 | def __setitem__(self, key, value): |
| 702 | Place.config({key: value}) |
| 703 | def forget(self): |
| 704 | self.tk.call('place', 'forget', self._w) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 705 | place_forget = forget |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 706 | def info(self): |
Guido van Rossum | 63e39ae | 1996-05-16 17:53:48 +0000 | [diff] [blame] | 707 | words = self.tk.splitlist( |
| 708 | self.tk.call('place', 'info', self._w)) |
| 709 | dict = {} |
| 710 | for i in range(0, len(words), 2): |
| 711 | key = words[i][1:] |
| 712 | value = words[i+1] |
| 713 | if value[:1] == '.': |
| 714 | value = self._nametowidget(value) |
| 715 | dict[key] = value |
| 716 | return dict |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 717 | place_info = info |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 718 | def slaves(self): |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 719 | return map(self._nametowidget, |
| 720 | self.tk.splitlist( |
| 721 | self.tk.call( |
| 722 | 'place', 'slaves', self._w))) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 723 | place_slaves = slaves |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 724 | |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 725 | class Grid: |
Guido van Rossum | 422cc7f | 1996-05-21 20:30:07 +0000 | [diff] [blame] | 726 | # Thanks to Masazumi Yoshikawa (yosikawa@isi.edu) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 727 | def config(self, cnf={}, **kw): |
| 728 | apply(self.tk.call, |
| 729 | ('grid', 'configure', self._w) |
| 730 | + self._options(cnf, kw)) |
| 731 | grid = config |
| 732 | def __setitem__(self, key, value): |
| 733 | Grid.config({key: value}) |
| 734 | def bbox(self, column, row): |
| 735 | return self._getints( |
| 736 | self.tk.call( |
| 737 | 'grid', 'bbox', self._w, column, row)) or None |
| 738 | grid_bbox = bbox |
Guido van Rossum | 422cc7f | 1996-05-21 20:30:07 +0000 | [diff] [blame] | 739 | def columnconfigure(self, index, cnf={}, **kw): |
| 740 | if type(cnf) is not DictionaryType and not kw: |
| 741 | options = self._options({cnf: None}) |
| 742 | else: |
| 743 | options = self._options(cnf, kw) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 744 | res = apply(self.tk.call, |
Guido van Rossum | 422cc7f | 1996-05-21 20:30:07 +0000 | [diff] [blame] | 745 | ('grid', 'columnconfigure', self._w, index) |
| 746 | + options) |
| 747 | if options == ('-minsize', None): |
| 748 | return self.tk.getint(res) or None |
| 749 | elif options == ('-weight', None): |
| 750 | return self.tk.getdouble(res) or None |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 751 | def forget(self): |
| 752 | self.tk.call('grid', 'forget', self._w) |
| 753 | grid_forget = forget |
| 754 | def info(self): |
| 755 | words = self.tk.splitlist( |
| 756 | self.tk.call('grid', 'info', self._w)) |
| 757 | dict = {} |
| 758 | for i in range(0, len(words), 2): |
| 759 | key = words[i][1:] |
| 760 | value = words[i+1] |
Guido van Rossum | a5f875f | 1996-05-16 17:50:07 +0000 | [diff] [blame] | 761 | if value[:1] == '.': |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 762 | value = self._nametowidget(value) |
| 763 | dict[key] = value |
| 764 | return dict |
| 765 | grid_info = info |
| 766 | def location(self, x, y): |
| 767 | return self._getints( |
| 768 | self.tk.call( |
| 769 | 'grid', 'location', self._w, x, y)) or None |
| 770 | _noarg_ = ['_noarg_'] |
| 771 | def propagate(self, flag=_noarg_): |
| 772 | if flag is Grid._noarg_: |
| 773 | return self._getboolean(self.tk.call( |
| 774 | 'grid', 'propagate', self._w)) |
| 775 | else: |
| 776 | self.tk.call('grid', 'propagate', self._w, flag) |
| 777 | grid_propagate = propagate |
Guido van Rossum | 422cc7f | 1996-05-21 20:30:07 +0000 | [diff] [blame] | 778 | def rowconfigure(self, index, cnf={}, **kw): |
| 779 | if type(cnf) is not DictionaryType and not kw: |
| 780 | options = self._options({cnf: None}) |
| 781 | else: |
| 782 | options = self._options(cnf, kw) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 783 | res = apply(self.tk.call, |
Guido van Rossum | 422cc7f | 1996-05-21 20:30:07 +0000 | [diff] [blame] | 784 | ('grid', 'rowconfigure', self._w, index) |
| 785 | + options) |
| 786 | if options == ('-minsize', None): |
| 787 | return self.tk.getint(res) or None |
| 788 | elif options == ('-weight', None): |
| 789 | return self.tk.getdouble(res) or None |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 790 | def size(self): |
| 791 | return self._getints( |
| 792 | self.tk.call('grid', 'size', self._w)) or None |
| 793 | def slaves(self, *args): |
| 794 | return map(self._nametowidget, |
| 795 | self.tk.splitlist( |
| 796 | apply(self.tk.call, |
| 797 | ('grid', 'slaves', self._w) + args))) |
| 798 | grid_slaves = slaves |
| 799 | |
| 800 | class Widget(Misc, Pack, Place, Grid): |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 801 | def _setup(self, master, cnf): |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 802 | global _default_root |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 803 | if not master: |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 804 | if not _default_root: |
| 805 | _default_root = Tk() |
| 806 | master = _default_root |
| 807 | if not _default_root: |
| 808 | _default_root = master |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 809 | self.master = master |
| 810 | self.tk = master.tk |
| 811 | if cnf.has_key('name'): |
| 812 | name = cnf['name'] |
| 813 | del cnf['name'] |
| 814 | else: |
| 815 | name = `id(self)` |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 816 | self._name = name |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 817 | if master._w=='.': |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 818 | self._w = '.' + name |
| 819 | else: |
| 820 | self._w = master._w + '.' + name |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 821 | self.children = {} |
| 822 | if self.master.children.has_key(self._name): |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame] | 823 | self.master.children[self._name].destroy() |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 824 | self.master.children[self._name] = self |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 825 | def __init__(self, master, widgetName, cnf={}, kw={}, extra=()): |
| 826 | if kw: |
| 827 | cnf = _cnfmerge((cnf, kw)) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 828 | self.widgetName = widgetName |
Guido van Rossum | 761c5ab | 1995-07-14 15:29:10 +0000 | [diff] [blame] | 829 | Widget._setup(self, master, cnf) |
Guido van Rossum | ad8b3ba | 1996-07-21 03:05:05 +0000 | [diff] [blame] | 830 | classes = [] |
| 831 | for k in cnf.keys(): |
| 832 | if type(k) is ClassType: |
| 833 | classes.append((k, cnf[k])) |
| 834 | del cnf[k] |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 835 | apply(self.tk.call, |
| 836 | (widgetName, self._w) + extra + self._options(cnf)) |
Guido van Rossum | ad8b3ba | 1996-07-21 03:05:05 +0000 | [diff] [blame] | 837 | for k, v in classes: |
| 838 | k.config(self, v) |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 839 | def config(self, cnf=None, **kw): |
| 840 | # XXX ought to generalize this so tag_config etc. can use it |
| 841 | if kw: |
| 842 | cnf = _cnfmerge((cnf, kw)) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 843 | elif cnf: |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 844 | cnf = _cnfmerge(cnf) |
Guido van Rossum | 9b68fd9 | 1994-06-23 07:40:14 +0000 | [diff] [blame] | 845 | if cnf is None: |
| 846 | cnf = {} |
| 847 | for x in self.tk.split( |
| 848 | self.tk.call(self._w, 'configure')): |
| 849 | cnf[x[0][1:]] = (x[0][1:],) + x[1:] |
| 850 | return cnf |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 851 | if type(cnf) is StringType: |
Guido van Rossum | 9b68fd9 | 1994-06-23 07:40:14 +0000 | [diff] [blame] | 852 | x = self.tk.split(self.tk.call( |
| 853 | self._w, 'configure', '-'+cnf)) |
| 854 | return (x[0][1:],) + x[1:] |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 855 | apply(self.tk.call, (self._w, 'configure') |
| 856 | + self._options(cnf)) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 857 | configure = config |
Guido van Rossum | 422cc7f | 1996-05-21 20:30:07 +0000 | [diff] [blame] | 858 | def cget(self, key): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 859 | return self.tk.call(self._w, 'cget', '-' + key) |
Guido van Rossum | 422cc7f | 1996-05-21 20:30:07 +0000 | [diff] [blame] | 860 | __getitem__ = cget |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 861 | def __setitem__(self, key, value): |
| 862 | Widget.config(self, {key: value}) |
Guido van Rossum | 9b68fd9 | 1994-06-23 07:40:14 +0000 | [diff] [blame] | 863 | def keys(self): |
| 864 | return map(lambda x: x[0][1:], |
| 865 | self.tk.split(self.tk.call(self._w, 'configure'))) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 866 | def __str__(self): |
| 867 | return self._w |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 868 | def destroy(self): |
| 869 | for c in self.children.values(): c.destroy() |
Guido van Rossum | f023ab0 | 1994-08-30 12:13:44 +0000 | [diff] [blame] | 870 | if self.master.children.has_key(self._name): |
| 871 | del self.master.children[self._name] |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 872 | self.tk.call('destroy', self._w) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 873 | def _do(self, name, args=()): |
Guido van Rossum | 761c5ab | 1995-07-14 15:29:10 +0000 | [diff] [blame] | 874 | return apply(self.tk.call, (self._w, name) + args) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 875 | |
| 876 | class Toplevel(Widget, Wm): |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 877 | def __init__(self, master=None, cnf={}, **kw): |
| 878 | if kw: |
| 879 | cnf = _cnfmerge((cnf, kw)) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 880 | extra = () |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 881 | for wmkey in ['screen', 'class_', 'class', 'visual', |
| 882 | 'colormap']: |
| 883 | if cnf.has_key(wmkey): |
| 884 | val = cnf[wmkey] |
| 885 | # TBD: a hack needed because some keys |
| 886 | # are not valid as keyword arguments |
| 887 | if wmkey[-1] == '_': opt = '-'+wmkey[:-1] |
| 888 | else: opt = '-'+wmkey |
| 889 | extra = extra + (opt, val) |
| 890 | del cnf[wmkey] |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 891 | Widget.__init__(self, master, 'toplevel', cnf, {}, extra) |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 892 | root = self._root() |
| 893 | self.iconname(root.iconname()) |
| 894 | self.title(root.title()) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 895 | |
| 896 | class Button(Widget): |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 897 | def __init__(self, master=None, cnf={}, **kw): |
| 898 | Widget.__init__(self, master, 'button', cnf, kw) |
Guido van Rossum | 761c5ab | 1995-07-14 15:29:10 +0000 | [diff] [blame] | 899 | def tkButtonEnter(self, *dummy): |
| 900 | self.tk.call('tkButtonEnter', self._w) |
| 901 | def tkButtonLeave(self, *dummy): |
| 902 | self.tk.call('tkButtonLeave', self._w) |
| 903 | def tkButtonDown(self, *dummy): |
| 904 | self.tk.call('tkButtonDown', self._w) |
| 905 | def tkButtonUp(self, *dummy): |
| 906 | self.tk.call('tkButtonUp', self._w) |
Guido van Rossum | 3626999 | 1996-05-16 17:11:27 +0000 | [diff] [blame] | 907 | def tkButtonInvoke(self, *dummy): |
| 908 | self.tk.call('tkButtonInvoke', self._w) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 909 | def flash(self): |
| 910 | self.tk.call(self._w, 'flash') |
| 911 | def invoke(self): |
| 912 | self.tk.call(self._w, 'invoke') |
| 913 | |
| 914 | # Indices: |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 915 | # XXX I don't like these -- take them away |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 916 | def AtEnd(): |
| 917 | return 'end' |
Guido van Rossum | 1e9e400 | 1994-06-20 09:09:51 +0000 | [diff] [blame] | 918 | def AtInsert(*args): |
| 919 | s = 'insert' |
| 920 | for a in args: |
| 921 | if a: s = s + (' ' + a) |
| 922 | return s |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 923 | def AtSelFirst(): |
| 924 | return 'sel.first' |
| 925 | def AtSelLast(): |
| 926 | return 'sel.last' |
| 927 | def At(x, y=None): |
Guido van Rossum | 5e0c25b | 1994-07-12 09:04:41 +0000 | [diff] [blame] | 928 | if y is None: |
| 929 | return '@' + `x` |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 930 | else: |
Guido van Rossum | 5e0c25b | 1994-07-12 09:04:41 +0000 | [diff] [blame] | 931 | return '@' + `x` + ',' + `y` |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 932 | |
| 933 | class Canvas(Widget): |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 934 | def __init__(self, master=None, cnf={}, **kw): |
| 935 | Widget.__init__(self, master, 'canvas', cnf, kw) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 936 | def addtag(self, *args): |
| 937 | self._do('addtag', args) |
Guido van Rossum | 9b68fd9 | 1994-06-23 07:40:14 +0000 | [diff] [blame] | 938 | def addtag_above(self, tagOrId): |
| 939 | self.addtag('above', tagOrId) |
| 940 | def addtag_all(self): |
| 941 | self.addtag('all') |
| 942 | def addtag_below(self, tagOrId): |
| 943 | self.addtag('below', tagOrId) |
| 944 | def addtag_closest(self, x, y, halo=None, start=None): |
| 945 | self.addtag('closest', x, y, halo, start) |
| 946 | def addtag_enclosed(self, x1, y1, x2, y2): |
| 947 | self.addtag('enclosed', x1, y1, x2, y2) |
| 948 | def addtag_overlapping(self, x1, y1, x2, y2): |
| 949 | self.addtag('overlapping', x1, y1, x2, y2) |
| 950 | def addtag_withtag(self, tagOrId): |
| 951 | self.addtag('withtag', tagOrId) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 952 | def bbox(self, *args): |
Guido van Rossum | 9b68fd9 | 1994-06-23 07:40:14 +0000 | [diff] [blame] | 953 | return self._getints(self._do('bbox', args)) or None |
Guido van Rossum | ef8f881 | 1994-08-08 12:47:33 +0000 | [diff] [blame] | 954 | def tag_unbind(self, tagOrId, sequence): |
| 955 | self.tk.call(self._w, 'bind', tagOrId, sequence, '') |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 956 | def tag_bind(self, tagOrId, sequence=None, func=None, add=None): |
Guido van Rossum | 421bb0e | 1996-07-21 02:19:32 +0000 | [diff] [blame] | 957 | return self._bind((self._w, 'bind', tagOrId), |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 958 | sequence, func, add) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 959 | def canvasx(self, screenx, gridspacing=None): |
Guido van Rossum | 761c5ab | 1995-07-14 15:29:10 +0000 | [diff] [blame] | 960 | return self.tk.getdouble(self.tk.call( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 961 | self._w, 'canvasx', screenx, gridspacing)) |
| 962 | def canvasy(self, screeny, gridspacing=None): |
Guido van Rossum | 761c5ab | 1995-07-14 15:29:10 +0000 | [diff] [blame] | 963 | return self.tk.getdouble(self.tk.call( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 964 | self._w, 'canvasy', screeny, gridspacing)) |
| 965 | def coords(self, *args): |
Guido van Rossum | c8b4791 | 1996-07-30 16:31:32 +0000 | [diff] [blame] | 966 | return map(self.tk.getdouble, |
Guido van Rossum | 9afdabf | 1996-07-30 20:16:21 +0000 | [diff] [blame] | 967 | self.tk.splitlist(self._do('coords', args))) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 968 | def _create(self, itemType, args, kw): # Args: (val, val, ..., cnf={}) |
Guido van Rossum | 08a4038 | 1994-06-21 11:44:21 +0000 | [diff] [blame] | 969 | args = _flatten(args) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 970 | cnf = args[-1] |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame] | 971 | if type(cnf) in (DictionaryType, TupleType): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 972 | args = args[:-1] |
| 973 | else: |
| 974 | cnf = {} |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame] | 975 | return self.tk.getint(apply( |
| 976 | self.tk.call, |
| 977 | (self._w, 'create', itemType) |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 978 | + args + self._options(cnf, kw))) |
| 979 | def create_arc(self, *args, **kw): |
| 980 | return self._create('arc', args, kw) |
| 981 | def create_bitmap(self, *args, **kw): |
| 982 | return self._create('bitmap', args, kw) |
| 983 | def create_image(self, *args, **kw): |
| 984 | return self._create('image', args, kw) |
| 985 | def create_line(self, *args, **kw): |
| 986 | return self._create('line', args, kw) |
| 987 | def create_oval(self, *args, **kw): |
| 988 | return self._create('oval', args, kw) |
| 989 | def create_polygon(self, *args, **kw): |
| 990 | return self._create('polygon', args, kw) |
| 991 | def create_rectangle(self, *args, **kw): |
| 992 | return self._create('rectangle', args, kw) |
| 993 | def create_text(self, *args, **kw): |
| 994 | return self._create('text', args, kw) |
| 995 | def create_window(self, *args, **kw): |
| 996 | return self._create('window', args, kw) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 997 | def dchars(self, *args): |
| 998 | self._do('dchars', args) |
| 999 | def delete(self, *args): |
| 1000 | self._do('delete', args) |
| 1001 | def dtag(self, *args): |
| 1002 | self._do('dtag', args) |
| 1003 | def find(self, *args): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1004 | return self._getints(self._do('find', args)) or () |
Guido van Rossum | 9b68fd9 | 1994-06-23 07:40:14 +0000 | [diff] [blame] | 1005 | def find_above(self, tagOrId): |
| 1006 | return self.find('above', tagOrId) |
| 1007 | def find_all(self): |
| 1008 | return self.find('all') |
| 1009 | def find_below(self, tagOrId): |
| 1010 | return self.find('below', tagOrId) |
| 1011 | def find_closest(self, x, y, halo=None, start=None): |
| 1012 | return self.find('closest', x, y, halo, start) |
| 1013 | def find_enclosed(self, x1, y1, x2, y2): |
| 1014 | return self.find('enclosed', x1, y1, x2, y2) |
| 1015 | def find_overlapping(self, x1, y1, x2, y2): |
| 1016 | return self.find('overlapping', x1, y1, x2, y2) |
| 1017 | def find_withtag(self, tagOrId): |
| 1018 | return self.find('withtag', tagOrId) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1019 | def focus(self, *args): |
| 1020 | return self._do('focus', args) |
| 1021 | def gettags(self, *args): |
| 1022 | return self.tk.splitlist(self._do('gettags', args)) |
| 1023 | def icursor(self, *args): |
| 1024 | self._do('icursor', args) |
| 1025 | def index(self, *args): |
| 1026 | return self.tk.getint(self._do('index', args)) |
| 1027 | def insert(self, *args): |
| 1028 | self._do('insert', args) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1029 | def itemcget(self, tagOrId, option): |
| 1030 | return self._do('itemcget', (tagOrId, '-'+option)) |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1031 | def itemconfig(self, tagOrId, cnf=None, **kw): |
| 1032 | if cnf is None and not kw: |
Guido van Rossum | 9b68fd9 | 1994-06-23 07:40:14 +0000 | [diff] [blame] | 1033 | cnf = {} |
| 1034 | for x in self.tk.split( |
| 1035 | self._do('itemconfigure', (tagOrId))): |
| 1036 | cnf[x[0][1:]] = (x[0][1:],) + x[1:] |
| 1037 | return cnf |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1038 | if type(cnf) == StringType and not kw: |
Guido van Rossum | 9b68fd9 | 1994-06-23 07:40:14 +0000 | [diff] [blame] | 1039 | x = self.tk.split(self._do('itemconfigure', |
| 1040 | (tagOrId, '-'+cnf,))) |
| 1041 | return (x[0][1:],) + x[1:] |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1042 | self._do('itemconfigure', (tagOrId,) |
| 1043 | + self._options(cnf, kw)) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1044 | itemconfigure = itemconfig |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1045 | def lower(self, *args): |
| 1046 | self._do('lower', args) |
| 1047 | def move(self, *args): |
| 1048 | self._do('move', args) |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1049 | def postscript(self, cnf={}, **kw): |
| 1050 | return self._do('postscript', self._options(cnf, kw)) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1051 | def tkraise(self, *args): |
| 1052 | self._do('raise', args) |
Guido van Rossum | 5e8d372 | 1994-06-20 08:12:01 +0000 | [diff] [blame] | 1053 | lift = tkraise |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1054 | def scale(self, *args): |
| 1055 | self._do('scale', args) |
| 1056 | def scan_mark(self, x, y): |
| 1057 | self.tk.call(self._w, 'scan', 'mark', x, y) |
| 1058 | def scan_dragto(self, x, y): |
| 1059 | self.tk.call(self._w, 'scan', 'dragto', x, y) |
| 1060 | def select_adjust(self, tagOrId, index): |
Guido van Rossum | 08a4038 | 1994-06-21 11:44:21 +0000 | [diff] [blame] | 1061 | self.tk.call(self._w, 'select', 'adjust', tagOrId, index) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1062 | def select_clear(self): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1063 | self.tk.call(self._w, 'select', 'clear') |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1064 | def select_from(self, tagOrId, index): |
Guido van Rossum | 761c5ab | 1995-07-14 15:29:10 +0000 | [diff] [blame] | 1065 | self.tk.call(self._w, 'select', 'set', tagOrId, index) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1066 | def select_item(self): |
| 1067 | self.tk.call(self._w, 'select', 'item') |
| 1068 | def select_to(self, tagOrId, index): |
Guido van Rossum | 08a4038 | 1994-06-21 11:44:21 +0000 | [diff] [blame] | 1069 | self.tk.call(self._w, 'select', 'to', tagOrId, index) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1070 | def type(self, tagOrId): |
Guido van Rossum | 08a4038 | 1994-06-21 11:44:21 +0000 | [diff] [blame] | 1071 | return self.tk.call(self._w, 'type', tagOrId) or None |
Guido van Rossum | 761c5ab | 1995-07-14 15:29:10 +0000 | [diff] [blame] | 1072 | def xview(self, *args): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1073 | if not args: |
| 1074 | return self._getdoubles(self.tk.call(self._w, 'xview')) |
Guido van Rossum | 761c5ab | 1995-07-14 15:29:10 +0000 | [diff] [blame] | 1075 | apply(self.tk.call, (self._w, 'xview')+args) |
| 1076 | def yview(self, *args): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1077 | if not args: |
| 1078 | return self._getdoubles(self.tk.call(self._w, 'yview')) |
Guido van Rossum | 761c5ab | 1995-07-14 15:29:10 +0000 | [diff] [blame] | 1079 | apply(self.tk.call, (self._w, 'yview')+args) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1080 | |
| 1081 | class Checkbutton(Widget): |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1082 | def __init__(self, master=None, cnf={}, **kw): |
| 1083 | Widget.__init__(self, master, 'checkbutton', cnf, kw) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1084 | def deselect(self): |
| 1085 | self.tk.call(self._w, 'deselect') |
| 1086 | def flash(self): |
| 1087 | self.tk.call(self._w, 'flash') |
| 1088 | def invoke(self): |
| 1089 | self.tk.call(self._w, 'invoke') |
| 1090 | def select(self): |
| 1091 | self.tk.call(self._w, 'select') |
| 1092 | def toggle(self): |
| 1093 | self.tk.call(self._w, 'toggle') |
| 1094 | |
| 1095 | class Entry(Widget): |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1096 | def __init__(self, master=None, cnf={}, **kw): |
| 1097 | Widget.__init__(self, master, 'entry', cnf, kw) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1098 | def delete(self, first, last=None): |
| 1099 | self.tk.call(self._w, 'delete', first, last) |
| 1100 | def get(self): |
| 1101 | return self.tk.call(self._w, 'get') |
| 1102 | def icursor(self, index): |
| 1103 | self.tk.call(self._w, 'icursor', index) |
| 1104 | def index(self, index): |
| 1105 | return self.tk.getint(self.tk.call( |
| 1106 | self._w, 'index', index)) |
| 1107 | def insert(self, index, string): |
| 1108 | self.tk.call(self._w, 'insert', index, string) |
| 1109 | def scan_mark(self, x): |
| 1110 | self.tk.call(self._w, 'scan', 'mark', x) |
| 1111 | def scan_dragto(self, x): |
| 1112 | self.tk.call(self._w, 'scan', 'dragto', x) |
Guido van Rossum | 422cc7f | 1996-05-21 20:30:07 +0000 | [diff] [blame] | 1113 | def selection_adjust(self, index): |
| 1114 | self.tk.call(self._w, 'selection', 'adjust', index) |
| 1115 | select_adjust = selection_adjust |
| 1116 | def selection_clear(self): |
| 1117 | self.tk.call(self._w, 'selection', 'clear') |
| 1118 | select_clear = selection_clear |
| 1119 | def selection_from(self, index): |
| 1120 | self.tk.call(self._w, 'selection', 'set', index) |
| 1121 | select_from = selection_from |
| 1122 | def selection_present(self): |
Guido van Rossum | 1d59df2 | 1995-08-11 14:21:06 +0000 | [diff] [blame] | 1123 | return self.tk.getboolean( |
Guido van Rossum | 422cc7f | 1996-05-21 20:30:07 +0000 | [diff] [blame] | 1124 | self.tk.call(self._w, 'selection', 'present')) |
| 1125 | select_present = selection_present |
| 1126 | def selection_range(self, start, end): |
| 1127 | self.tk.call(self._w, 'selection', 'range', start, end) |
| 1128 | select_range = selection_range |
| 1129 | def selection_to(self, index): |
| 1130 | self.tk.call(self._w, 'selection', 'to', index) |
| 1131 | select_to = selection_to |
| 1132 | def xview(self, index): |
| 1133 | self.tk.call(self._w, 'xview', index) |
| 1134 | def xview_moveto(self, fraction): |
| 1135 | self.tk.call(self._w, 'xview', 'moveto', fraction) |
| 1136 | def xview_scroll(self, number, what): |
| 1137 | self.tk.call(self._w, 'xview', 'scroll', number, what) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1138 | |
| 1139 | class Frame(Widget): |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1140 | def __init__(self, master=None, cnf={}, **kw): |
| 1141 | cnf = _cnfmerge((cnf, kw)) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1142 | extra = () |
| 1143 | if cnf.has_key('class'): |
| 1144 | extra = ('-class', cnf['class']) |
| 1145 | del cnf['class'] |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1146 | Widget.__init__(self, master, 'frame', cnf, {}, extra) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1147 | |
| 1148 | class Label(Widget): |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1149 | def __init__(self, master=None, cnf={}, **kw): |
| 1150 | Widget.__init__(self, master, 'label', cnf, kw) |
Guido van Rossum | 761c5ab | 1995-07-14 15:29:10 +0000 | [diff] [blame] | 1151 | |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1152 | class Listbox(Widget): |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1153 | def __init__(self, master=None, cnf={}, **kw): |
| 1154 | Widget.__init__(self, master, 'listbox', cnf, kw) |
Guido van Rossum | 46f92d2 | 1995-10-11 17:41:00 +0000 | [diff] [blame] | 1155 | def activate(self, index): |
| 1156 | self.tk.call(self._w, 'activate', index) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1157 | def bbox(self, *args): |
| 1158 | return self._getints(self._do('bbox', args)) or None |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1159 | def curselection(self): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1160 | # XXX Ought to apply self._getints()... |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1161 | return self.tk.splitlist(self.tk.call( |
| 1162 | self._w, 'curselection')) |
| 1163 | def delete(self, first, last=None): |
| 1164 | self.tk.call(self._w, 'delete', first, last) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1165 | def get(self, first, last=None): |
| 1166 | if last: |
| 1167 | return self.tk.splitlist(self.tk.call( |
| 1168 | self._w, 'get', first, last)) |
| 1169 | else: |
| 1170 | return self.tk.call(self._w, 'get', first) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1171 | def insert(self, index, *elements): |
| 1172 | apply(self.tk.call, |
| 1173 | (self._w, 'insert', index) + elements) |
| 1174 | def nearest(self, y): |
| 1175 | return self.tk.getint(self.tk.call( |
| 1176 | self._w, 'nearest', y)) |
| 1177 | def scan_mark(self, x, y): |
| 1178 | self.tk.call(self._w, 'scan', 'mark', x, y) |
| 1179 | def scan_dragto(self, x, y): |
| 1180 | self.tk.call(self._w, 'scan', 'dragto', x, y) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1181 | def see(self, index): |
| 1182 | self.tk.call(self._w, 'see', index) |
| 1183 | def index(self, index): |
| 1184 | i = self.tk.call(self._w, 'index', index) |
| 1185 | if i == 'none': return None |
| 1186 | return self.tk.getint(i) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1187 | def select_adjust(self, index): |
| 1188 | self.tk.call(self._w, 'select', 'adjust', index) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1189 | def select_anchor(self, index): |
| 1190 | self.tk.call(self._w, 'selection', 'anchor', index) |
| 1191 | def select_clear(self, first, last=None): |
| 1192 | self.tk.call(self._w, |
| 1193 | 'selection', 'clear', first, last) |
| 1194 | def select_includes(self, index): |
| 1195 | return self.tk.getboolean(self.tk.call( |
| 1196 | self._w, 'selection', 'includes', index)) |
| 1197 | def select_set(self, first, last=None): |
| 1198 | self.tk.call(self._w, 'selection', 'set', first, last) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1199 | def size(self): |
| 1200 | return self.tk.getint(self.tk.call(self._w, 'size')) |
Guido van Rossum | 761c5ab | 1995-07-14 15:29:10 +0000 | [diff] [blame] | 1201 | def xview(self, *what): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1202 | if not what: |
| 1203 | return self._getdoubles(self.tk.call(self._w, 'xview')) |
Guido van Rossum | 761c5ab | 1995-07-14 15:29:10 +0000 | [diff] [blame] | 1204 | apply(self.tk.call, (self._w, 'xview')+what) |
| 1205 | def yview(self, *what): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1206 | if not what: |
| 1207 | return self._getdoubles(self.tk.call(self._w, 'yview')) |
Guido van Rossum | 761c5ab | 1995-07-14 15:29:10 +0000 | [diff] [blame] | 1208 | apply(self.tk.call, (self._w, 'yview')+what) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1209 | |
| 1210 | class Menu(Widget): |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1211 | def __init__(self, master=None, cnf={}, **kw): |
| 1212 | Widget.__init__(self, master, 'menu', cnf, kw) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1213 | def tk_bindForTraversal(self): |
| 1214 | self.tk.call('tk_bindForTraversal', self._w) |
| 1215 | def tk_mbPost(self): |
| 1216 | self.tk.call('tk_mbPost', self._w) |
| 1217 | def tk_mbUnpost(self): |
| 1218 | self.tk.call('tk_mbUnpost') |
| 1219 | def tk_traverseToMenu(self, char): |
| 1220 | self.tk.call('tk_traverseToMenu', self._w, char) |
| 1221 | def tk_traverseWithinMenu(self, char): |
| 1222 | self.tk.call('tk_traverseWithinMenu', self._w, char) |
| 1223 | def tk_getMenuButtons(self): |
| 1224 | return self.tk.call('tk_getMenuButtons', self._w) |
| 1225 | def tk_nextMenu(self, count): |
| 1226 | self.tk.call('tk_nextMenu', count) |
| 1227 | def tk_nextMenuEntry(self, count): |
| 1228 | self.tk.call('tk_nextMenuEntry', count) |
| 1229 | def tk_invokeMenu(self): |
| 1230 | self.tk.call('tk_invokeMenu', self._w) |
| 1231 | def tk_firstMenu(self): |
| 1232 | self.tk.call('tk_firstMenu', self._w) |
| 1233 | def tk_mbButtonDown(self): |
| 1234 | self.tk.call('tk_mbButtonDown', self._w) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1235 | def tk_popup(self, x, y, entry=""): |
| 1236 | self.tk.call('tk_popup', self._w, x, y, entry) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1237 | def activate(self, index): |
| 1238 | self.tk.call(self._w, 'activate', index) |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1239 | def add(self, itemType, cnf={}, **kw): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1240 | apply(self.tk.call, (self._w, 'add', itemType) |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1241 | + self._options(cnf, kw)) |
Guido van Rossum | a1db48b | 1995-10-09 22:37:28 +0000 | [diff] [blame] | 1242 | def add_cascade(self, cnf={}, **kw): |
| 1243 | self.add('cascade', cnf or kw) |
| 1244 | def add_checkbutton(self, cnf={}, **kw): |
| 1245 | self.add('checkbutton', cnf or kw) |
| 1246 | def add_command(self, cnf={}, **kw): |
| 1247 | self.add('command', cnf or kw) |
| 1248 | def add_radiobutton(self, cnf={}, **kw): |
| 1249 | self.add('radiobutton', cnf or kw) |
| 1250 | def add_separator(self, cnf={}, **kw): |
| 1251 | self.add('separator', cnf or kw) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1252 | def delete(self, index1, index2=None): |
| 1253 | self.tk.call(self._w, 'delete', index1, index2) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1254 | def entryconfig(self, index, cnf=None, **kw): |
| 1255 | if cnf is None and not kw: |
| 1256 | cnf = {} |
| 1257 | for x in self.tk.split(apply(self.tk.call, |
| 1258 | (self._w, 'entryconfigure', index))): |
| 1259 | cnf[x[0][1:]] = (x[0][1:],) + x[1:] |
| 1260 | return cnf |
| 1261 | if type(cnf) == StringType and not kw: |
| 1262 | x = self.tk.split(apply(self.tk.call, |
| 1263 | (self._w, 'entryconfigure', index, '-'+cnf))) |
| 1264 | return (x[0][1:],) + x[1:] |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1265 | apply(self.tk.call, (self._w, 'entryconfigure', index) |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1266 | + self._options(cnf, kw)) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1267 | entryconfigure = entryconfig |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1268 | def index(self, index): |
Guido van Rossum | 535cf0c | 1994-06-27 07:55:59 +0000 | [diff] [blame] | 1269 | i = self.tk.call(self._w, 'index', index) |
| 1270 | if i == 'none': return None |
| 1271 | return self.tk.getint(i) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1272 | def invoke(self, index): |
| 1273 | return self.tk.call(self._w, 'invoke', index) |
| 1274 | def post(self, x, y): |
| 1275 | self.tk.call(self._w, 'post', x, y) |
| 1276 | def unpost(self): |
| 1277 | self.tk.call(self._w, 'unpost') |
| 1278 | def yposition(self, index): |
| 1279 | return self.tk.getint(self.tk.call( |
| 1280 | self._w, 'yposition', index)) |
| 1281 | |
| 1282 | class Menubutton(Widget): |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1283 | def __init__(self, master=None, cnf={}, **kw): |
| 1284 | Widget.__init__(self, master, 'menubutton', cnf, kw) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1285 | |
| 1286 | class Message(Widget): |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1287 | def __init__(self, master=None, cnf={}, **kw): |
| 1288 | Widget.__init__(self, master, 'message', cnf, kw) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1289 | |
| 1290 | class Radiobutton(Widget): |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1291 | def __init__(self, master=None, cnf={}, **kw): |
| 1292 | Widget.__init__(self, master, 'radiobutton', cnf, kw) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1293 | def deselect(self): |
| 1294 | self.tk.call(self._w, 'deselect') |
| 1295 | def flash(self): |
| 1296 | self.tk.call(self._w, 'flash') |
| 1297 | def invoke(self): |
| 1298 | self.tk.call(self._w, 'invoke') |
| 1299 | def select(self): |
| 1300 | self.tk.call(self._w, 'select') |
| 1301 | |
| 1302 | class Scale(Widget): |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1303 | def __init__(self, master=None, cnf={}, **kw): |
| 1304 | Widget.__init__(self, master, 'scale', cnf, kw) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1305 | def get(self): |
| 1306 | return self.tk.getint(self.tk.call(self._w, 'get')) |
| 1307 | def set(self, value): |
| 1308 | self.tk.call(self._w, 'set', value) |
| 1309 | |
| 1310 | class Scrollbar(Widget): |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1311 | def __init__(self, master=None, cnf={}, **kw): |
| 1312 | Widget.__init__(self, master, 'scrollbar', cnf, kw) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1313 | def activate(self, index): |
| 1314 | self.tk.call(self._w, 'activate', index) |
| 1315 | def delta(self, deltax, deltay): |
| 1316 | return self.getdouble(self.tk.call( |
| 1317 | self._w, 'delta', deltax, deltay)) |
| 1318 | def fraction(self, x, y): |
| 1319 | return self.getdouble(self.tk.call( |
| 1320 | self._w, 'fraction', x, y)) |
| 1321 | def identify(self, x, y): |
| 1322 | return self.tk.call(self._w, 'identify', x, y) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1323 | def get(self): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1324 | return self._getdoubles(self.tk.call(self._w, 'get')) |
Guido van Rossum | 761c5ab | 1995-07-14 15:29:10 +0000 | [diff] [blame] | 1325 | def set(self, *args): |
| 1326 | apply(self.tk.call, (self._w, 'set')+args) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1327 | |
| 1328 | class Text(Widget): |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1329 | def __init__(self, master=None, cnf={}, **kw): |
| 1330 | Widget.__init__(self, master, 'text', cnf, kw) |
Guido van Rossum | 761c5ab | 1995-07-14 15:29:10 +0000 | [diff] [blame] | 1331 | self.bind('<Delete>', self.bspace) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1332 | def bbox(self, *args): |
| 1333 | return self._getints(self._do('bbox', args)) or None |
Guido van Rossum | 761c5ab | 1995-07-14 15:29:10 +0000 | [diff] [blame] | 1334 | def bspace(self, *args): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1335 | self.delete('insert') |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1336 | def tk_textSelectTo(self, index): |
| 1337 | self.tk.call('tk_textSelectTo', self._w, index) |
| 1338 | def tk_textBackspace(self): |
| 1339 | self.tk.call('tk_textBackspace', self._w) |
| 1340 | def tk_textIndexCloser(self, a, b, c): |
| 1341 | self.tk.call('tk_textIndexCloser', self._w, a, b, c) |
| 1342 | def tk_textResetAnchor(self, index): |
| 1343 | self.tk.call('tk_textResetAnchor', self._w, index) |
| 1344 | def compare(self, index1, op, index2): |
| 1345 | return self.tk.getboolean(self.tk.call( |
| 1346 | self._w, 'compare', index1, op, index2)) |
| 1347 | def debug(self, boolean=None): |
| 1348 | return self.tk.getboolean(self.tk.call( |
| 1349 | self._w, 'debug', boolean)) |
| 1350 | def delete(self, index1, index2=None): |
| 1351 | self.tk.call(self._w, 'delete', index1, index2) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1352 | def dlineinfo(self, index): |
| 1353 | return self._getints(self.tk.call(self._w, 'dlineinfo', index)) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1354 | def get(self, index1, index2=None): |
| 1355 | return self.tk.call(self._w, 'get', index1, index2) |
| 1356 | def index(self, index): |
| 1357 | return self.tk.call(self._w, 'index', index) |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1358 | def insert(self, index, chars, *args): |
| 1359 | apply(self.tk.call, (self._w, 'insert', index, chars)+args) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1360 | def mark_gravity(self, markName, direction=None): |
| 1361 | return apply(self.tk.call, |
| 1362 | (self._w, 'mark', 'gravity', markName, direction)) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1363 | def mark_names(self): |
| 1364 | return self.tk.splitlist(self.tk.call( |
| 1365 | self._w, 'mark', 'names')) |
| 1366 | def mark_set(self, markName, index): |
| 1367 | self.tk.call(self._w, 'mark', 'set', markName, index) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1368 | def mark_unset(self, *markNames): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1369 | apply(self.tk.call, (self._w, 'mark', 'unset') + markNames) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1370 | def scan_mark(self, x, y): |
| 1371 | self.tk.call(self._w, 'scan', 'mark', x, y) |
| 1372 | def scan_dragto(self, x, y): |
| 1373 | self.tk.call(self._w, 'scan', 'dragto', x, y) |
Guido van Rossum | 96ebbd3 | 1995-09-30 17:05:26 +0000 | [diff] [blame] | 1374 | def search(self, pattern, index, stopindex=None, |
| 1375 | forwards=None, backwards=None, exact=None, |
| 1376 | regexp=None, nocase=None, count=None): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1377 | args = [self._w, 'search'] |
| 1378 | if forwards: args.append('-forwards') |
| 1379 | if backwards: args.append('-backwards') |
| 1380 | if exact: args.append('-exact') |
| 1381 | if regexp: args.append('-regexp') |
| 1382 | if nocase: args.append('-nocase') |
| 1383 | if count: args.append('-count'); args.append(count) |
| 1384 | if pattern[0] == '-': args.append('--') |
| 1385 | args.append(pattern) |
| 1386 | args.append(index) |
| 1387 | if stopindex: args.append(stopindex) |
| 1388 | return apply(self.tk.call, tuple(args)) |
| 1389 | def see(self, index): |
| 1390 | self.tk.call(self._w, 'see', index) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1391 | def tag_add(self, tagName, index1, index2=None): |
| 1392 | self.tk.call( |
| 1393 | self._w, 'tag', 'add', tagName, index1, index2) |
Guido van Rossum | ef8f881 | 1994-08-08 12:47:33 +0000 | [diff] [blame] | 1394 | def tag_unbind(self, tagName, sequence): |
| 1395 | self.tk.call(self._w, 'tag', 'bind', tagName, sequence, '') |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1396 | def tag_bind(self, tagName, sequence, func, add=None): |
| 1397 | return self._bind((self._w, 'tag', 'bind', tagName), |
| 1398 | sequence, func, add) |
| 1399 | def tag_cget(self, tagName, option): |
| 1400 | return self.tk.call(self._w, 'tag', 'cget', tagName, option) |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1401 | def tag_config(self, tagName, cnf={}, **kw): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1402 | if type(cnf) == StringType: |
| 1403 | x = self.tk.split(self.tk.call( |
| 1404 | self._w, 'tag', 'configure', tagName, '-'+cnf)) |
| 1405 | return (x[0][1:],) + x[1:] |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1406 | apply(self.tk.call, |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1407 | (self._w, 'tag', 'configure', tagName) |
| 1408 | + self._options(cnf, kw)) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1409 | tag_configure = tag_config |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame] | 1410 | def tag_delete(self, *tagNames): |
Guido van Rossum | 2a39031 | 1994-07-06 10:20:11 +0000 | [diff] [blame] | 1411 | apply(self.tk.call, (self._w, 'tag', 'delete') + tagNames) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1412 | def tag_lower(self, tagName, belowThis=None): |
Guido van Rossum | 97aeca1 | 1994-07-07 13:12:12 +0000 | [diff] [blame] | 1413 | self.tk.call(self._w, 'tag', 'lower', tagName, belowThis) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1414 | def tag_names(self, index=None): |
| 1415 | return self.tk.splitlist( |
| 1416 | self.tk.call(self._w, 'tag', 'names', index)) |
| 1417 | def tag_nextrange(self, tagName, index1, index2=None): |
| 1418 | return self.tk.splitlist(self.tk.call( |
Guido van Rossum | 903abee | 1995-03-20 15:09:13 +0000 | [diff] [blame] | 1419 | self._w, 'tag', 'nextrange', tagName, index1, index2)) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1420 | def tag_raise(self, tagName, aboveThis=None): |
| 1421 | self.tk.call( |
| 1422 | self._w, 'tag', 'raise', tagName, aboveThis) |
| 1423 | def tag_ranges(self, tagName): |
| 1424 | return self.tk.splitlist(self.tk.call( |
| 1425 | self._w, 'tag', 'ranges', tagName)) |
| 1426 | def tag_remove(self, tagName, index1, index2=None): |
| 1427 | self.tk.call( |
Guido van Rossum | 5113569 | 1994-07-06 21:16:58 +0000 | [diff] [blame] | 1428 | self._w, 'tag', 'remove', tagName, index1, index2) |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1429 | def window_cget(self, index, option): |
| 1430 | return self.tk.call(self._w, 'window', 'cget', index, option) |
| 1431 | def window_config(self, index, cnf={}, **kw): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1432 | if type(cnf) == StringType: |
| 1433 | x = self.tk.split(self.tk.call( |
| 1434 | self._w, 'window', 'configure', |
| 1435 | index, '-'+cnf)) |
| 1436 | return (x[0][1:],) + x[1:] |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1437 | apply(self.tk.call, |
| 1438 | (self._w, 'window', 'configure', index) |
| 1439 | + self._options(cnf, kw)) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1440 | window_configure = window_config |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1441 | def window_create(self, index, cnf={}, **kw): |
| 1442 | apply(self.tk.call, |
| 1443 | (self._w, 'window', 'create', index) |
| 1444 | + self._options(cnf, kw)) |
| 1445 | def window_names(self): |
| 1446 | return self.tk.splitlist( |
| 1447 | self.tk.call(self._w, 'window', 'names')) |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1448 | def xview(self, *what): |
| 1449 | if not what: |
| 1450 | return self._getdoubles(self.tk.call(self._w, 'xview')) |
| 1451 | apply(self.tk.call, (self._w, 'xview')+what) |
Guido van Rossum | 761c5ab | 1995-07-14 15:29:10 +0000 | [diff] [blame] | 1452 | def yview(self, *what): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1453 | if not what: |
| 1454 | return self._getdoubles(self.tk.call(self._w, 'yview')) |
Guido van Rossum | 761c5ab | 1995-07-14 15:29:10 +0000 | [diff] [blame] | 1455 | apply(self.tk.call, (self._w, 'yview')+what) |
| 1456 | def yview_pickplace(self, *what): |
| 1457 | apply(self.tk.call, (self._w, 'yview', '-pickplace')+what) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1458 | |
Guido van Rossum | bf4d8f9 | 1995-09-01 20:35:37 +0000 | [diff] [blame] | 1459 | class OptionMenu(Widget): |
| 1460 | def __init__(self, master, variable, value, *values): |
| 1461 | self.widgetName = 'tk_optionMenu' |
| 1462 | Widget._setup(self, master, {}) |
| 1463 | self.menuname = apply( |
| 1464 | self.tk.call, |
| 1465 | (self.widgetName, self._w, variable, value) + values) |
| 1466 | |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1467 | class Image: |
| 1468 | def __init__(self, imgtype, name=None, cnf={}, **kw): |
| 1469 | self.name = None |
| 1470 | master = _default_root |
| 1471 | if not master: raise RuntimeError, 'Too early to create image' |
| 1472 | self.tk = master.tk |
| 1473 | if not name: name = `id(self)` |
| 1474 | if kw and cnf: cnf = _cnfmerge((cnf, kw)) |
| 1475 | elif kw: cnf = kw |
| 1476 | options = () |
| 1477 | for k, v in cnf.items(): |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1478 | if callable(v): |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1479 | v = self._register(v) |
| 1480 | options = options + ('-'+k, v) |
| 1481 | apply(self.tk.call, |
| 1482 | ('image', 'create', imgtype, name,) + options) |
| 1483 | self.name = name |
| 1484 | def __str__(self): return self.name |
| 1485 | def __del__(self): |
| 1486 | if self.name: |
| 1487 | self.tk.call('image', 'delete', self.name) |
Guido van Rossum | 71b1a90 | 1995-09-18 21:54:35 +0000 | [diff] [blame] | 1488 | def __setitem__(self, key, value): |
| 1489 | self.tk.call(self.name, 'configure', '-'+key, value) |
| 1490 | def __getitem__(self, key): |
| 1491 | return self.tk.call(self.name, 'configure', '-'+key) |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1492 | def height(self): |
| 1493 | return self.tk.getint( |
| 1494 | self.tk.call('image', 'height', self.name)) |
| 1495 | def type(self): |
| 1496 | return self.tk.call('image', 'type', self.name) |
| 1497 | def width(self): |
| 1498 | return self.tk.getint( |
| 1499 | self.tk.call('image', 'width', self.name)) |
| 1500 | |
| 1501 | class PhotoImage(Image): |
| 1502 | def __init__(self, name=None, cnf={}, **kw): |
| 1503 | apply(Image.__init__, (self, 'photo', name, cnf), kw) |
Guido van Rossum | 96ebbd3 | 1995-09-30 17:05:26 +0000 | [diff] [blame] | 1504 | def blank(self): |
| 1505 | self.tk.call(self.name, 'blank') |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1506 | def cget(self, option): |
| 1507 | return self.tk.call(self.name, 'cget', '-' + option) |
Guido van Rossum | 96ebbd3 | 1995-09-30 17:05:26 +0000 | [diff] [blame] | 1508 | # XXX config |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1509 | def __getitem__(self, key): |
| 1510 | return self.tk.call(self.name, 'cget', '-' + key) |
| 1511 | def copy(self): |
| 1512 | destImage = PhotoImage() |
| 1513 | self.tk.call(destImage, 'copy', self.name) |
| 1514 | return destImage |
| 1515 | def zoom(self,x,y=''): |
| 1516 | destImage = PhotoImage() |
| 1517 | if y=='': y=x |
| 1518 | self.tk.call(destImage, 'copy', self.name, '-zoom',x,y) |
| 1519 | return destImage |
| 1520 | def subsample(self,x,y=''): |
| 1521 | destImage = PhotoImage() |
| 1522 | if y=='': y=x |
| 1523 | self.tk.call(destImage, 'copy', self.name, '-subsample',x,y) |
| 1524 | return destImage |
Guido van Rossum | 96ebbd3 | 1995-09-30 17:05:26 +0000 | [diff] [blame] | 1525 | def get(self, x, y): |
| 1526 | return self.tk.call(self.name, 'get', x, y) |
| 1527 | def put(self, data, to=None): |
| 1528 | args = (self.name, 'put', data) |
| 1529 | if to: |
| 1530 | args = args + to |
| 1531 | apply(self.tk.call, args) |
| 1532 | # XXX read |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1533 | def write(self, filename, format=None, from_coords=None): |
| 1534 | args = (self.name, 'write', filename) |
| 1535 | if format: |
| 1536 | args = args + ('-format', format) |
| 1537 | if from_coords: |
| 1538 | args = args + ('-from',) + tuple(from_coords) |
| 1539 | apply(self.tk.call, args) |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1540 | |
| 1541 | class BitmapImage(Image): |
| 1542 | def __init__(self, name=None, cnf={}, **kw): |
| 1543 | apply(Image.__init__, (self, 'bitmap', name, cnf), kw) |
| 1544 | |
| 1545 | def image_names(): return _default_root.tk.call('image', 'names') |
| 1546 | def image_types(): return _default_root.tk.call('image', 'types') |
| 1547 | |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 1548 | ###################################################################### |
| 1549 | # Extensions: |
| 1550 | |
| 1551 | class Studbutton(Button): |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1552 | def __init__(self, master=None, cnf={}, **kw): |
| 1553 | Widget.__init__(self, master, 'studbutton', cnf, kw) |
Guido van Rossum | 761c5ab | 1995-07-14 15:29:10 +0000 | [diff] [blame] | 1554 | self.bind('<Any-Enter>', self.tkButtonEnter) |
| 1555 | self.bind('<Any-Leave>', self.tkButtonLeave) |
| 1556 | self.bind('<1>', self.tkButtonDown) |
| 1557 | self.bind('<ButtonRelease-1>', self.tkButtonUp) |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 1558 | |
| 1559 | class Tributton(Button): |
Guido van Rossum | 35f67fb | 1995-08-04 03:50:29 +0000 | [diff] [blame] | 1560 | def __init__(self, master=None, cnf={}, **kw): |
| 1561 | Widget.__init__(self, master, 'tributton', cnf, kw) |
Guido van Rossum | 761c5ab | 1995-07-14 15:29:10 +0000 | [diff] [blame] | 1562 | self.bind('<Any-Enter>', self.tkButtonEnter) |
| 1563 | self.bind('<Any-Leave>', self.tkButtonLeave) |
| 1564 | self.bind('<1>', self.tkButtonDown) |
| 1565 | self.bind('<ButtonRelease-1>', self.tkButtonUp) |
| 1566 | self['fg'] = self['bg'] |
| 1567 | self['activebackground'] = self['bg'] |
Guido van Rossum | 37dcab1 | 1996-05-16 16:00:19 +0000 | [diff] [blame] | 1568 | |
| 1569 | |
| 1570 | # Emacs cruft |
| 1571 | # Local Variables: |
| 1572 | # py-indent-offset: 8 |
| 1573 | # End: |