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 | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 3 | import tkinter |
| 4 | from tkinter import TclError |
| 5 | |
| 6 | class _Dummy: |
| 7 | def meth(self): return |
| 8 | |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame^] | 9 | def _func(): |
| 10 | pass |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 11 | |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame^] | 12 | FunctionType = type(_func) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 13 | ClassType = type(_Dummy) |
| 14 | MethodType = type(_Dummy.meth) |
Guido van Rossum | 08a4038 | 1994-06-21 11:44:21 +0000 | [diff] [blame] | 15 | StringType = type('') |
Guido van Rossum | 67ef5f3 | 1994-06-20 13:39:14 +0000 | [diff] [blame] | 16 | TupleType = type(()) |
| 17 | ListType = type([]) |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame^] | 18 | DictionaryType = type({}) |
| 19 | NoneType = type(None) |
Guido van Rossum | 08a4038 | 1994-06-21 11:44:21 +0000 | [diff] [blame] | 20 | CallableTypes = (FunctionType, MethodType) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 21 | |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame^] | 22 | def _flatten(tuple): |
| 23 | res = () |
| 24 | for item in tuple: |
| 25 | if type(item) in (TupleType, ListType): |
| 26 | res = res + _flatten(item) |
| 27 | else: |
| 28 | res = res + (item,) |
| 29 | return res |
| 30 | |
| 31 | def _cnfmerge(cnfs): |
| 32 | if type(cnfs) in (NoneType, DictionaryType, StringType): |
| 33 | return cnfs |
| 34 | else: |
| 35 | cnf = {} |
| 36 | for c in _flatten(cnfs): |
| 37 | for k, v in c.items(): |
| 38 | cnf[k] = v |
| 39 | return cnf |
| 40 | |
| 41 | class Event: |
| 42 | pass |
| 43 | |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 44 | _default_root = None |
| 45 | |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 46 | def _tkerror(err): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 47 | pass |
| 48 | |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 49 | _varnum = 0 |
| 50 | class Variable: |
| 51 | def __init__(self, master=None): |
| 52 | global _default_root |
| 53 | global _varnum |
| 54 | if master: |
| 55 | self._tk = master.tk |
| 56 | else: |
| 57 | self._tk = _default_root.tk |
| 58 | self._name = 'PY_VAR' + `_varnum` |
| 59 | _varnum = _varnum + 1 |
| 60 | def __del__(self): |
| 61 | self._tk.unsetvar(self._name) |
| 62 | def __str__(self): |
| 63 | return self._name |
| 64 | def __call__(self, value=None): |
| 65 | if value == None: |
| 66 | return self.get() |
| 67 | else: |
| 68 | self.set(value) |
| 69 | def set(self, value): |
| 70 | return self._tk.setvar(self._name, value) |
| 71 | |
| 72 | class StringVar(Variable): |
| 73 | def __init__(self, master=None): |
| 74 | Variable.__init__(self, master) |
| 75 | def get(self): |
| 76 | return self._tk.getvar(self._name) |
| 77 | |
| 78 | class IntVar(Variable): |
| 79 | def __init__(self, master=None): |
| 80 | Variable.__init__(self, master) |
| 81 | def get(self): |
| 82 | return self._tk.getint(self._tk.getvar(self._name)) |
| 83 | |
| 84 | class DoubleVar(Variable): |
| 85 | def __init__(self, master=None): |
| 86 | Variable.__init__(self, master) |
| 87 | def get(self): |
| 88 | return self._tk.getdouble(self._tk.getvar(self._name)) |
| 89 | |
| 90 | class BooleanVar(Variable): |
| 91 | def __init__(self, master=None): |
| 92 | Variable.__init__(self, master) |
| 93 | def get(self): |
| 94 | return self._tk.getboolean(self._tk.getvar(self._name)) |
| 95 | |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame^] | 96 | def mainloop(): |
| 97 | _default_root.tk.mainloop() |
| 98 | |
| 99 | def getint(s): |
| 100 | return _default_root.tk.getint(s) |
| 101 | |
| 102 | def getdouble(s): |
| 103 | return _default_root.tk.getdouble(s) |
| 104 | |
| 105 | def getboolean(s): |
| 106 | return _default_root.tk.getboolean(s) |
| 107 | |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 108 | class Misc: |
| 109 | def tk_strictMotif(self, boolean=None): |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame^] | 110 | return self.tk.getboolean(self.tk.call( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 111 | 'set', 'tk_strictMotif', boolean)) |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 112 | def tk_menuBar(self, *args): |
| 113 | apply(self.tk.call, ('tk_menuBar', self._w) + args) |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame^] | 114 | def wait_variable(self, name='PY_VAR'): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 115 | self.tk.call('tkwait', 'variable', name) |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame^] | 116 | waitvar = wait_variable # XXX b/w compat |
Guido van Rossum | 9beb932 | 1994-06-27 23:15:31 +0000 | [diff] [blame] | 117 | def wait_window(self, window=None): |
| 118 | if window == None: |
| 119 | window = self |
| 120 | self.tk.call('tkwait', 'window', window._w) |
| 121 | def wait_visibility(self, window=None): |
| 122 | if window == None: |
| 123 | window = self |
| 124 | self.tk.call('tkwait', 'visibility', window._w) |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 125 | def setvar(self, name='PY_VAR', value='1'): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 126 | self.tk.setvar(name, value) |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 127 | def getvar(self, name='PY_VAR'): |
Guido van Rossum | 5e8d372 | 1994-06-20 08:12:01 +0000 | [diff] [blame] | 128 | return self.tk.getvar(name) |
| 129 | def getint(self, s): |
| 130 | return self.tk.getint(s) |
Guido van Rossum | 1e9e400 | 1994-06-20 09:09:51 +0000 | [diff] [blame] | 131 | def getdouble(self, s): |
| 132 | return self.tk.getdouble(s) |
| 133 | def getboolean(self, s): |
| 134 | return self.tk.getboolean(s) |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 135 | def focus_set(self): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 136 | self.tk.call('focus', self._w) |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 137 | focus = focus_set # XXX b/w compat? |
| 138 | def focus_default_set(self): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 139 | self.tk.call('focus', 'default', self._w) |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 140 | def focus_default_none(self): |
| 141 | self.tk.call('focus', 'default', 'none') |
| 142 | focus_default = focus_default_set |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 143 | def focus_none(self): |
| 144 | self.tk.call('focus', 'none') |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 145 | def focus_get(self): |
| 146 | name = self.tk.call('focus') |
| 147 | if name == 'none': return None |
| 148 | return self._nametowidget(name) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 149 | def after(self, ms, func=None, *args): |
| 150 | if not func: |
| 151 | self.tk.call('after', ms) |
| 152 | else: |
Guido van Rossum | 08a4038 | 1994-06-21 11:44:21 +0000 | [diff] [blame] | 153 | # XXX Disgusting hack to clean up after calling func |
| 154 | tmp = [] |
| 155 | def callit(func=func, args=args, tk=self.tk, tmp=tmp): |
| 156 | try: |
| 157 | apply(func, args) |
| 158 | finally: |
| 159 | tk.deletecommand(tmp[0]) |
| 160 | name = self._register(callit) |
| 161 | tmp.append(name) |
| 162 | self.tk.call('after', ms, name) |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 163 | # XXX grab current w/o window argument |
| 164 | def grab_current(self): |
| 165 | name = self.tk.call('grab', 'current', self._w) |
| 166 | if not name: return None |
| 167 | return self._nametowidget(name) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 168 | def grab_release(self): |
| 169 | self.tk.call('grab', 'release', self._w) |
| 170 | def grab_set(self): |
| 171 | self.tk.call('grab', 'set', self._w) |
| 172 | def grab_set_global(self): |
| 173 | self.tk.call('grab', 'set', '-global', self._w) |
| 174 | def grab_status(self): |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 175 | status = self.tk.call('grab', 'status', self._w) |
| 176 | if status == 'none': status = None |
| 177 | return status |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 178 | def lower(self, belowThis=None): |
| 179 | self.tk.call('lower', self._w, belowThis) |
| 180 | def selection_clear(self): |
| 181 | self.tk.call('selection', 'clear', self._w) |
| 182 | def selection_get(self, type=None): |
Guido van Rossum | bd84b04 | 1994-07-04 10:48:25 +0000 | [diff] [blame] | 183 | return self.tk.call('selection', 'get', type) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 184 | def selection_handle(self, func, type=None, format=None): |
| 185 | name = self._register(func) |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 186 | self.tk.call('selection', 'handle', self._w, |
| 187 | name, type, format) |
| 188 | def selection_own(self, func=None): |
| 189 | name = self._register(func) |
| 190 | self.tk.call('selection', 'own', self._w, name) |
| 191 | def selection_own_get(self): |
| 192 | return self._nametowidget(self.tk.call('selection', 'own')) |
| 193 | def send(self, interp, cmd, *args): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 194 | return apply(self.tk.call, ('send', interp, cmd) + args) |
Guido van Rossum | 5e8d372 | 1994-06-20 08:12:01 +0000 | [diff] [blame] | 195 | def lower(self, belowThis=None): |
| 196 | self.tk.call('lift', self._w, belowThis) |
| 197 | def tkraise(self, aboveThis=None): |
| 198 | self.tk.call('raise', self._w, aboveThis) |
| 199 | lift = tkraise |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 200 | def colormodel(self, value=None): |
| 201 | return self.tk.call('tk', 'colormodel', self._w, value) |
| 202 | def winfo_atom(self, name): |
| 203 | return self.tk.getint(self.tk.call('winfo', 'atom', name)) |
| 204 | def winfo_atomname(self, id): |
| 205 | return self.tk.call('winfo', 'atomname', id) |
| 206 | def winfo_cells(self): |
| 207 | return self.tk.getint( |
| 208 | self.tk.call('winfo', 'cells', self._w)) |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 209 | def winfo_children(self): |
| 210 | return map(self._nametowidget, |
| 211 | self.tk.splitlist(self.tk.call( |
| 212 | 'winfo', 'children', self._w))) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 213 | def winfo_class(self): |
| 214 | return self.tk.call('winfo', 'class', self._w) |
| 215 | def winfo_containing(self, rootX, rootY): |
| 216 | return self.tk.call('winfo', 'containing', rootx, rootY) |
| 217 | def winfo_depth(self): |
| 218 | return self.tk.getint(self.tk.call('winfo', 'depth', self._w)) |
| 219 | def winfo_exists(self): |
| 220 | return self.tk.getint( |
| 221 | self.tk.call('winfo', 'exists', self._w)) |
| 222 | def winfo_fpixels(self, number): |
| 223 | return self.tk.getdouble(self.tk.call( |
| 224 | 'winfo', 'fpixels', self._w, number)) |
| 225 | def winfo_geometry(self): |
| 226 | return self.tk.call('winfo', 'geometry', self._w) |
| 227 | def winfo_height(self): |
| 228 | return self.tk.getint( |
| 229 | self.tk.call('winfo', 'height', self._w)) |
| 230 | def winfo_id(self): |
| 231 | return self.tk.getint( |
| 232 | self.tk.call('winfo', 'id', self._w)) |
| 233 | def winfo_interps(self): |
| 234 | return self.tk.splitlist( |
| 235 | self.tk.call('winfo', 'interps')) |
| 236 | def winfo_ismapped(self): |
| 237 | return self.tk.getint( |
| 238 | self.tk.call('winfo', 'ismapped', self._w)) |
| 239 | def winfo_name(self): |
| 240 | return self.tk.call('winfo', 'name', self._w) |
| 241 | def winfo_parent(self): |
| 242 | return self.tk.call('winfo', 'parent', self._w) |
| 243 | def winfo_pathname(self, id): |
| 244 | return self.tk.call('winfo', 'pathname', id) |
| 245 | def winfo_pixels(self, number): |
| 246 | return self.tk.getint( |
| 247 | self.tk.call('winfo', 'pixels', self._w, number)) |
| 248 | def winfo_reqheight(self): |
| 249 | return self.tk.getint( |
| 250 | self.tk.call('winfo', 'reqheight', self._w)) |
| 251 | def winfo_reqwidth(self): |
| 252 | return self.tk.getint( |
| 253 | self.tk.call('winfo', 'reqwidth', self._w)) |
| 254 | def winfo_rgb(self, color): |
| 255 | return self._getints( |
| 256 | self.tk.call('winfo', 'rgb', self._w, color)) |
| 257 | def winfo_rootx(self): |
| 258 | return self.tk.getint( |
| 259 | self.tk.call('winfo', 'rootx', self._w)) |
| 260 | def winfo_rooty(self): |
| 261 | return self.tk.getint( |
| 262 | self.tk.call('winfo', 'rooty', self._w)) |
| 263 | def winfo_screen(self): |
| 264 | return self.tk.call('winfo', 'screen', self._w) |
| 265 | def winfo_screencells(self): |
| 266 | return self.tk.getint( |
| 267 | self.tk.call('winfo', 'screencells', self._w)) |
| 268 | def winfo_screendepth(self): |
| 269 | return self.tk.getint( |
| 270 | self.tk.call('winfo', 'screendepth', self._w)) |
| 271 | def winfo_screenheight(self): |
| 272 | return self.tk.getint( |
| 273 | self.tk.call('winfo', 'screenheight', self._w)) |
| 274 | def winfo_screenmmheight(self): |
| 275 | return self.tk.getint( |
| 276 | self.tk.call('winfo', 'screenmmheight', self._w)) |
| 277 | def winfo_screenmmwidth(self): |
| 278 | return self.tk.getint( |
| 279 | self.tk.call('winfo', 'screenmmwidth', self._w)) |
| 280 | def winfo_screenvisual(self): |
| 281 | return self.tk.call('winfo', 'screenvisual', self._w) |
| 282 | def winfo_screenwidth(self): |
| 283 | return self.tk.getint( |
| 284 | self.tk.call('winfo', 'screenwidth', self._w)) |
| 285 | def winfo_toplevel(self): |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 286 | return self._nametowidget(self.tk.call( |
| 287 | 'winfo', 'toplevel', self._w)) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 288 | def winfo_visual(self): |
| 289 | return self.tk.call('winfo', 'visual', self._w) |
| 290 | def winfo_vrootheight(self): |
| 291 | return self.tk.getint( |
| 292 | self.tk.call('winfo', 'vrootheight', self._w)) |
| 293 | def winfo_vrootwidth(self): |
| 294 | return self.tk.getint( |
| 295 | self.tk.call('winfo', 'vrootwidth', self._w)) |
| 296 | def winfo_vrootx(self): |
| 297 | return self.tk.getint( |
| 298 | self.tk.call('winfo', 'vrootx', self._w)) |
| 299 | def winfo_vrooty(self): |
| 300 | return self.tk.getint( |
| 301 | self.tk.call('winfo', 'vrooty', self._w)) |
| 302 | def winfo_width(self): |
| 303 | return self.tk.getint( |
| 304 | self.tk.call('winfo', 'width', self._w)) |
| 305 | def winfo_x(self): |
| 306 | return self.tk.getint( |
| 307 | self.tk.call('winfo', 'x', self._w)) |
| 308 | def winfo_y(self): |
| 309 | return self.tk.getint( |
| 310 | self.tk.call('winfo', 'y', self._w)) |
| 311 | def update(self): |
| 312 | self.tk.call('update') |
| 313 | def update_idletasks(self): |
| 314 | self.tk.call('update', 'idletasks') |
| 315 | def bind(self, sequence, func, add=''): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 316 | if add: add = '+' |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 317 | name = self._register(func, self._substitute) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 318 | self.tk.call('bind', self._w, sequence, |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 319 | (add + name,) + self._subst_format) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 320 | def bind_all(self, sequence, func, add=''): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 321 | if add: add = '+' |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 322 | name = self._register(func, self._substitute) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 323 | self.tk.call('bind', 'all' , sequence, |
Guido van Rossum | bd84b04 | 1994-07-04 10:48:25 +0000 | [diff] [blame] | 324 | (add + name,) + self._subst_format) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 325 | def bind_class(self, className, sequence, func, add=''): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 326 | if add: add = '+' |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 327 | name = self._register(func, self._substitute) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 328 | self.tk.call('bind', className , sequence, |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 329 | (add + name,) + self._subst_format) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 330 | def mainloop(self): |
| 331 | self.tk.mainloop() |
| 332 | def quit(self): |
| 333 | self.tk.quit() |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 334 | def _getints(self, string): |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 335 | if not string: return None |
| 336 | res = () |
| 337 | for v in self.tk.splitlist(string): |
| 338 | res = res + (self.tk.getint(v),) |
| 339 | return res |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 340 | def _getboolean(self, string): |
| 341 | if string: |
| 342 | return self.tk.getboolean(string) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 343 | def _options(self, cnf): |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame^] | 344 | cnf = _cnfmerge(cnf) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 345 | res = () |
| 346 | for k, v in cnf.items(): |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame^] | 347 | if type(v) in CallableTypes: |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 348 | v = self._register(v) |
| 349 | res = res + ('-'+k, v) |
| 350 | return res |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 351 | def _nametowidget(self, name): |
| 352 | w = self |
| 353 | if name[0] == '.': |
| 354 | w = w._root() |
| 355 | name = name[1:] |
| 356 | from string import find |
| 357 | while name: |
| 358 | i = find(name, '.') |
| 359 | if i >= 0: |
| 360 | name, tail = name[:i], name[i+1:] |
| 361 | else: |
| 362 | tail = '' |
| 363 | w = w.children[name] |
| 364 | name = tail |
| 365 | return w |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 366 | def _register(self, func, subst=None): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 367 | f = _CallSafely(func, subst).__call__ |
| 368 | name = `id(f)` |
| 369 | if hasattr(func, 'im_func'): |
| 370 | func = func.im_func |
| 371 | if hasattr(func, 'func_name') and \ |
| 372 | type(func.func_name) == type(''): |
| 373 | name = name + func.func_name |
| 374 | self.tk.createcommand(name, f) |
| 375 | return name |
Guido van Rossum | 9beb932 | 1994-06-27 23:15:31 +0000 | [diff] [blame] | 376 | register = _register |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 377 | def _root(self): |
| 378 | w = self |
| 379 | while w.master: w = w.master |
| 380 | return w |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 381 | _subst_format = ('%#', '%b', '%f', '%h', '%k', |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 382 | '%s', '%t', '%w', '%x', '%y', |
| 383 | '%A', '%E', '%K', '%N', '%W', '%T', '%X', '%Y') |
| 384 | def _substitute(self, *args): |
| 385 | tk = self.tk |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 386 | if len(args) != len(self._subst_format): return args |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 387 | nsign, b, f, h, k, s, t, w, x, y, A, E, K, N, W, T, X, Y = args |
| 388 | # Missing: (a, c, d, m, o, v, B, R) |
| 389 | e = Event() |
| 390 | e.serial = tk.getint(nsign) |
| 391 | e.num = tk.getint(b) |
| 392 | try: e.focus = tk.getboolean(f) |
| 393 | except TclError: pass |
| 394 | e.height = tk.getint(h) |
| 395 | e.keycode = tk.getint(k) |
| 396 | e.state = tk.getint(s) |
| 397 | e.time = tk.getint(t) |
| 398 | e.width = tk.getint(w) |
| 399 | e.x = tk.getint(x) |
| 400 | e.y = tk.getint(y) |
| 401 | e.char = A |
| 402 | try: e.send_event = tk.getboolean(E) |
| 403 | except TclError: pass |
| 404 | e.keysym = K |
| 405 | e.keysym_num = tk.getint(N) |
| 406 | e.type = T |
| 407 | e.widget = self._nametowidget(W) |
| 408 | e.x_root = tk.getint(X) |
| 409 | e.y_root = tk.getint(Y) |
| 410 | return (e,) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 411 | |
| 412 | class _CallSafely: |
| 413 | def __init__(self, func, subst=None): |
| 414 | self.func = func |
| 415 | self.subst = subst |
| 416 | def __call__(self, *args): |
| 417 | if self.subst: |
| 418 | args = self.apply_func(self.subst, args) |
| 419 | args = self.apply_func(self.func, args) |
| 420 | def apply_func(self, func, args): |
| 421 | import sys |
| 422 | try: |
| 423 | return apply(func, args) |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 424 | except SystemExit, msg: |
| 425 | raise SystemExit, msg |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 426 | except: |
| 427 | try: |
| 428 | try: |
| 429 | t = sys.exc_traceback |
| 430 | while t: |
| 431 | sys.stderr.write( |
| 432 | ' %s, line %s\n' % |
| 433 | (t.tb_frame.f_code, |
| 434 | t.tb_lineno)) |
| 435 | t = t.tb_next |
| 436 | finally: |
| 437 | sys.stderr.write('%s: %s\n' % |
| 438 | (sys.exc_type, |
| 439 | sys.exc_value)) |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 440 | (sys.last_type, |
| 441 | sys.last_value, |
| 442 | sys.last_traceback) = (sys.exc_type, |
| 443 | sys.exc_value, |
| 444 | sys.exc_traceback) |
| 445 | import pdb |
| 446 | pdb.pm() |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 447 | except: |
| 448 | print '*** Error in error handling ***' |
| 449 | print sys.exc_type, ':', sys.exc_value |
| 450 | |
| 451 | class Wm: |
| 452 | def aspect(self, |
| 453 | minNumer=None, minDenom=None, |
| 454 | maxNumer=None, maxDenom=None): |
| 455 | return self._getints( |
| 456 | self.tk.call('wm', 'aspect', self._w, |
| 457 | minNumer, minDenom, |
| 458 | maxNumer, maxDenom)) |
| 459 | def client(self, name=None): |
| 460 | return self.tk.call('wm', 'client', self._w, name) |
| 461 | def command(self, value=None): |
| 462 | return self.tk.call('wm', 'command', self._w, value) |
| 463 | def deiconify(self): |
| 464 | return self.tk.call('wm', 'deiconify', self._w) |
| 465 | def focusmodel(self, model=None): |
| 466 | return self.tk.call('wm', 'focusmodel', self._w, model) |
| 467 | def frame(self): |
| 468 | return self.tk.call('wm', 'frame', self._w) |
| 469 | def geometry(self, newGeometry=None): |
| 470 | return self.tk.call('wm', 'geometry', self._w, newGeometry) |
| 471 | def grid(self, |
| 472 | baseWidht=None, baseHeight=None, |
| 473 | widthInc=None, heightInc=None): |
| 474 | return self._getints(self.tk.call( |
| 475 | 'wm', 'grid', self._w, |
| 476 | baseWidht, baseHeight, widthInc, heightInc)) |
| 477 | def group(self, pathName=None): |
| 478 | return self.tk.call('wm', 'group', self._w, pathName) |
| 479 | def iconbitmap(self, bitmap=None): |
| 480 | return self.tk.call('wm', 'iconbitmap', self._w, bitmap) |
| 481 | def iconify(self): |
| 482 | return self.tk.call('wm', 'iconify', self._w) |
| 483 | def iconmask(self, bitmap=None): |
| 484 | return self.tk.call('wm', 'iconmask', self._w, bitmap) |
| 485 | def iconname(self, newName=None): |
| 486 | return self.tk.call('wm', 'iconname', self._w, newName) |
| 487 | def iconposition(self, x=None, y=None): |
| 488 | return self._getints(self.tk.call( |
| 489 | 'wm', 'iconposition', self._w, x, y)) |
| 490 | def iconwindow(self, pathName=None): |
| 491 | return self.tk.call('wm', 'iconwindow', self._w, pathName) |
| 492 | def maxsize(self, width=None, height=None): |
| 493 | return self._getints(self.tk.call( |
| 494 | 'wm', 'maxsize', self._w, width, height)) |
| 495 | def minsize(self, width=None, height=None): |
| 496 | return self._getints(self.tk.call( |
| 497 | 'wm', 'minsize', self._w, width, height)) |
| 498 | def overrideredirect(self, boolean=None): |
| 499 | return self._getboolean(self.tk.call( |
| 500 | 'wm', 'overrideredirect', self._w, boolean)) |
| 501 | def positionfrom(self, who=None): |
| 502 | return self.tk.call('wm', 'positionfrom', self._w, who) |
| 503 | def protocol(self, name=None, func=None): |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame^] | 504 | if type(func) in CallableTypes: |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 505 | command = self._register(func) |
| 506 | else: |
| 507 | command = func |
| 508 | return self.tk.call( |
| 509 | 'wm', 'protocol', self._w, name, command) |
| 510 | def sizefrom(self, who=None): |
| 511 | return self.tk.call('wm', 'sizefrom', self._w, who) |
| 512 | def state(self): |
| 513 | return self.tk.call('wm', 'state', self._w) |
| 514 | def title(self, string=None): |
| 515 | return self.tk.call('wm', 'title', self._w, string) |
| 516 | def transient(self, master=None): |
| 517 | return self.tk.call('wm', 'transient', self._w, master) |
| 518 | def withdraw(self): |
| 519 | return self.tk.call('wm', 'withdraw', self._w) |
| 520 | |
| 521 | class Tk(Misc, Wm): |
| 522 | _w = '.' |
| 523 | def __init__(self, screenName=None, baseName=None, className='Tk'): |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 524 | self.master = None |
| 525 | self.children = {} |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 526 | if baseName is None: |
| 527 | import sys, os |
| 528 | baseName = os.path.basename(sys.argv[0]) |
| 529 | if baseName[-3:] == '.py': baseName = baseName[:-3] |
| 530 | self.tk = tkinter.create(screenName, baseName, className) |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 531 | self.tk.createcommand('tkerror', _tkerror) |
| 532 | def destroy(self): |
| 533 | for c in self.children.values(): c.destroy() |
Guido van Rossum | bd84b04 | 1994-07-04 10:48:25 +0000 | [diff] [blame] | 534 | ## del self.master.children[self._name] |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 535 | self.tk.call('destroy', self._w) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 536 | def __str__(self): |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 537 | return self._w |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 538 | |
| 539 | class Pack: |
| 540 | def config(self, cnf={}): |
| 541 | apply(self.tk.call, |
| 542 | ('pack', 'configure', self._w) |
| 543 | + self._options(cnf)) |
| 544 | pack = config |
| 545 | def __setitem__(self, key, value): |
| 546 | Pack.config({key: value}) |
| 547 | def forget(self): |
| 548 | self.tk.call('pack', 'forget', self._w) |
| 549 | def newinfo(self): |
| 550 | return self.tk.call('pack', 'newinfo', self._w) |
| 551 | info = newinfo |
| 552 | def propagate(self, boolean=None): |
| 553 | if boolean: |
| 554 | self.tk.call('pack', 'propagate', self._w) |
| 555 | else: |
| 556 | return self._getboolean(self.tk.call( |
| 557 | 'pack', 'propagate', self._w)) |
| 558 | def slaves(self): |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 559 | return map(self._nametowidget, |
| 560 | self.tk.splitlist( |
| 561 | self.tk.call('pack', 'slaves', self._w))) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 562 | |
| 563 | class Place: |
| 564 | def config(self, cnf={}): |
| 565 | apply(self.tk.call, |
| 566 | ('place', 'configure', self._w) |
| 567 | + self._options(cnf)) |
| 568 | place = config |
| 569 | def __setitem__(self, key, value): |
| 570 | Place.config({key: value}) |
| 571 | def forget(self): |
| 572 | self.tk.call('place', 'forget', self._w) |
| 573 | def info(self): |
| 574 | return self.tk.call('place', 'info', self._w) |
| 575 | def slaves(self): |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 576 | return map(self._nametowidget, |
| 577 | self.tk.splitlist( |
| 578 | self.tk.call( |
| 579 | 'place', 'slaves', self._w))) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 580 | |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 581 | class Widget(Misc, Pack, Place): |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 582 | def _setup(self, master, cnf): |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 583 | global _default_root |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 584 | if not master: |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 585 | if not _default_root: |
| 586 | _default_root = Tk() |
| 587 | master = _default_root |
| 588 | if not _default_root: |
| 589 | _default_root = master |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 590 | self.master = master |
| 591 | self.tk = master.tk |
| 592 | if cnf.has_key('name'): |
| 593 | name = cnf['name'] |
| 594 | del cnf['name'] |
| 595 | else: |
| 596 | name = `id(self)` |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 597 | self._name = name |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 598 | if master._w=='.': |
| 599 | self._w = '.' + name |
| 600 | else: |
| 601 | self._w = master._w + '.' + name |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 602 | self.children = {} |
| 603 | if self.master.children.has_key(self._name): |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame^] | 604 | self.master.children[self._name].destroy() |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 605 | self.master.children[self._name] = self |
| 606 | def __init__(self, master, widgetName, cnf={}, extra=()): |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame^] | 607 | cnf = _cnfmerge(cnf) |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 608 | Widget._setup(self, master, cnf) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 609 | self.widgetName = widgetName |
| 610 | apply(self.tk.call, (widgetName, self._w) + extra) |
| 611 | Widget.config(self, cnf) |
Guido van Rossum | 9b68fd9 | 1994-06-23 07:40:14 +0000 | [diff] [blame] | 612 | def config(self, cnf=None): |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame^] | 613 | + cnf = _cnfmerge(cnf) |
Guido van Rossum | 9b68fd9 | 1994-06-23 07:40:14 +0000 | [diff] [blame] | 614 | if cnf is None: |
| 615 | cnf = {} |
| 616 | for x in self.tk.split( |
| 617 | self.tk.call(self._w, 'configure')): |
| 618 | cnf[x[0][1:]] = (x[0][1:],) + x[1:] |
| 619 | return cnf |
| 620 | if type(cnf) == StringType: |
| 621 | x = self.tk.split(self.tk.call( |
| 622 | self._w, 'configure', '-'+cnf)) |
| 623 | return (x[0][1:],) + x[1:] |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 624 | for k in cnf.keys(): |
| 625 | if type(k) == ClassType: |
| 626 | k.config(self, cnf[k]) |
| 627 | del cnf[k] |
| 628 | apply(self.tk.call, (self._w, 'configure') |
| 629 | + self._options(cnf)) |
| 630 | def __getitem__(self, key): |
Guido van Rossum | 535cf0c | 1994-06-27 07:55:59 +0000 | [diff] [blame] | 631 | v = self.tk.splitlist(self.tk.call( |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 632 | self._w, 'configure', '-' + key)) |
| 633 | return v[4] |
| 634 | def __setitem__(self, key, value): |
| 635 | Widget.config(self, {key: value}) |
Guido van Rossum | 9b68fd9 | 1994-06-23 07:40:14 +0000 | [diff] [blame] | 636 | def keys(self): |
| 637 | return map(lambda x: x[0][1:], |
| 638 | self.tk.split(self.tk.call(self._w, 'configure'))) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 639 | def __str__(self): |
| 640 | return self._w |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 641 | def destroy(self): |
| 642 | for c in self.children.values(): c.destroy() |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 643 | self.tk.call('destroy', self._w) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 644 | def _do(self, name, args=()): |
Guido van Rossum | 67ef5f3 | 1994-06-20 13:39:14 +0000 | [diff] [blame] | 645 | return apply(self.tk.call, (self._w, name) + args) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 646 | |
| 647 | class Toplevel(Widget, Wm): |
| 648 | def __init__(self, master=None, cnf={}): |
| 649 | extra = () |
| 650 | if cnf.has_key('screen'): |
| 651 | extra = ('-screen', cnf['screen']) |
| 652 | del cnf['screen'] |
| 653 | if cnf.has_key('class'): |
| 654 | extra = extra + ('-class', cnf['class']) |
| 655 | del cnf['class'] |
| 656 | Widget.__init__(self, master, 'toplevel', cnf, extra) |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 657 | root = self._root() |
| 658 | self.iconname(root.iconname()) |
| 659 | self.title(root.title()) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 660 | |
| 661 | class Button(Widget): |
| 662 | def __init__(self, master=None, cnf={}): |
| 663 | Widget.__init__(self, master, 'button', cnf) |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 664 | def tk_butEnter(self, *dummy): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 665 | self.tk.call('tk_butEnter', self._w) |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 666 | def tk_butLeave(self, *dummy): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 667 | self.tk.call('tk_butLeave', self._w) |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 668 | def tk_butDown(self, *dummy): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 669 | self.tk.call('tk_butDown', self._w) |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 670 | def tk_butUp(self, *dummy): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 671 | self.tk.call('tk_butUp', self._w) |
| 672 | def flash(self): |
| 673 | self.tk.call(self._w, 'flash') |
| 674 | def invoke(self): |
| 675 | self.tk.call(self._w, 'invoke') |
| 676 | |
| 677 | # Indices: |
| 678 | def AtEnd(): |
| 679 | return 'end' |
Guido van Rossum | 1e9e400 | 1994-06-20 09:09:51 +0000 | [diff] [blame] | 680 | def AtInsert(*args): |
| 681 | s = 'insert' |
| 682 | for a in args: |
| 683 | if a: s = s + (' ' + a) |
| 684 | return s |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 685 | def AtSelFirst(): |
| 686 | return 'sel.first' |
| 687 | def AtSelLast(): |
| 688 | return 'sel.last' |
| 689 | def At(x, y=None): |
| 690 | if y: |
| 691 | return '@' + `x` + ',' + `y` |
| 692 | else: |
| 693 | return '@' + `x` |
| 694 | |
| 695 | class Canvas(Widget): |
| 696 | def __init__(self, master=None, cnf={}): |
| 697 | Widget.__init__(self, master, 'canvas', cnf) |
| 698 | def addtag(self, *args): |
| 699 | self._do('addtag', args) |
Guido van Rossum | 9b68fd9 | 1994-06-23 07:40:14 +0000 | [diff] [blame] | 700 | def addtag_above(self, tagOrId): |
| 701 | self.addtag('above', tagOrId) |
| 702 | def addtag_all(self): |
| 703 | self.addtag('all') |
| 704 | def addtag_below(self, tagOrId): |
| 705 | self.addtag('below', tagOrId) |
| 706 | def addtag_closest(self, x, y, halo=None, start=None): |
| 707 | self.addtag('closest', x, y, halo, start) |
| 708 | def addtag_enclosed(self, x1, y1, x2, y2): |
| 709 | self.addtag('enclosed', x1, y1, x2, y2) |
| 710 | def addtag_overlapping(self, x1, y1, x2, y2): |
| 711 | self.addtag('overlapping', x1, y1, x2, y2) |
| 712 | def addtag_withtag(self, tagOrId): |
| 713 | self.addtag('withtag', tagOrId) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 714 | def bbox(self, *args): |
Guido van Rossum | 9b68fd9 | 1994-06-23 07:40:14 +0000 | [diff] [blame] | 715 | return self._getints(self._do('bbox', args)) or None |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 716 | def bind(self, tagOrId, sequence, func, add=''): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 717 | if add: add='+' |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 718 | name = self._register(func, self._substitute) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 719 | self.tk.call(self._w, 'bind', tagOrId, sequence, |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 720 | (add + name,) + self._subst_format) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 721 | def canvasx(self, screenx, gridspacing=None): |
| 722 | return self.tk.getint(self.tk.call( |
| 723 | self._w, 'canvasx', screenx, gridspacing)) |
| 724 | def canvasy(self, screeny, gridspacing=None): |
| 725 | return self.tk.getint(self.tk.call( |
| 726 | self._w, 'canvasy', screeny, gridspacing)) |
| 727 | def coords(self, *args): |
| 728 | return self._do('coords', args) |
| 729 | def _create(self, itemType, args): # Args: (value, value, ..., cnf={}) |
Guido van Rossum | 08a4038 | 1994-06-21 11:44:21 +0000 | [diff] [blame] | 730 | args = _flatten(args) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 731 | cnf = args[-1] |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame^] | 732 | if type(cnf) in (DictionaryType, TupleType): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 733 | args = args[:-1] |
| 734 | else: |
| 735 | cnf = {} |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame^] | 736 | return self.tk.getint(apply( |
| 737 | self.tk.call, |
| 738 | (self._w, 'create', itemType) |
| 739 | + args + self._options(cnf))) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 740 | def create_arc(self, *args): |
Guido van Rossum | 67ef5f3 | 1994-06-20 13:39:14 +0000 | [diff] [blame] | 741 | return Canvas._create(self, 'arc', args) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 742 | def create_bitmap(self, *args): |
Guido van Rossum | 67ef5f3 | 1994-06-20 13:39:14 +0000 | [diff] [blame] | 743 | return Canvas._create(self, 'bitmap', args) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 744 | def create_line(self, *args): |
Guido van Rossum | 67ef5f3 | 1994-06-20 13:39:14 +0000 | [diff] [blame] | 745 | return Canvas._create(self, 'line', args) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 746 | def create_oval(self, *args): |
Guido van Rossum | 67ef5f3 | 1994-06-20 13:39:14 +0000 | [diff] [blame] | 747 | return Canvas._create(self, 'oval', args) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 748 | def create_polygon(self, *args): |
Guido van Rossum | 67ef5f3 | 1994-06-20 13:39:14 +0000 | [diff] [blame] | 749 | return Canvas._create(self, 'polygon', args) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 750 | def create_rectangle(self, *args): |
Guido van Rossum | 67ef5f3 | 1994-06-20 13:39:14 +0000 | [diff] [blame] | 751 | return Canvas._create(self, 'rectangle', args) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 752 | def create_text(self, *args): |
Guido van Rossum | 67ef5f3 | 1994-06-20 13:39:14 +0000 | [diff] [blame] | 753 | return Canvas._create(self, 'text', args) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 754 | def create_window(self, *args): |
Guido van Rossum | 67ef5f3 | 1994-06-20 13:39:14 +0000 | [diff] [blame] | 755 | return Canvas._create(self, 'window', args) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 756 | def dchars(self, *args): |
| 757 | self._do('dchars', args) |
| 758 | def delete(self, *args): |
| 759 | self._do('delete', args) |
| 760 | def dtag(self, *args): |
| 761 | self._do('dtag', args) |
| 762 | def find(self, *args): |
Guido van Rossum | 08a4038 | 1994-06-21 11:44:21 +0000 | [diff] [blame] | 763 | return self._getints(self._do('find', args)) |
Guido van Rossum | 9b68fd9 | 1994-06-23 07:40:14 +0000 | [diff] [blame] | 764 | def find_above(self, tagOrId): |
| 765 | return self.find('above', tagOrId) |
| 766 | def find_all(self): |
| 767 | return self.find('all') |
| 768 | def find_below(self, tagOrId): |
| 769 | return self.find('below', tagOrId) |
| 770 | def find_closest(self, x, y, halo=None, start=None): |
| 771 | return self.find('closest', x, y, halo, start) |
| 772 | def find_enclosed(self, x1, y1, x2, y2): |
| 773 | return self.find('enclosed', x1, y1, x2, y2) |
| 774 | def find_overlapping(self, x1, y1, x2, y2): |
| 775 | return self.find('overlapping', x1, y1, x2, y2) |
| 776 | def find_withtag(self, tagOrId): |
| 777 | return self.find('withtag', tagOrId) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 778 | def focus(self, *args): |
| 779 | return self._do('focus', args) |
| 780 | def gettags(self, *args): |
| 781 | return self.tk.splitlist(self._do('gettags', args)) |
| 782 | def icursor(self, *args): |
| 783 | self._do('icursor', args) |
| 784 | def index(self, *args): |
| 785 | return self.tk.getint(self._do('index', args)) |
| 786 | def insert(self, *args): |
| 787 | self._do('insert', args) |
Guido van Rossum | 08a4038 | 1994-06-21 11:44:21 +0000 | [diff] [blame] | 788 | def itemconfig(self, tagOrId, cnf=None): |
| 789 | if cnf is None: |
Guido van Rossum | 9b68fd9 | 1994-06-23 07:40:14 +0000 | [diff] [blame] | 790 | cnf = {} |
| 791 | for x in self.tk.split( |
| 792 | self._do('itemconfigure', (tagOrId))): |
| 793 | cnf[x[0][1:]] = (x[0][1:],) + x[1:] |
| 794 | return cnf |
Guido van Rossum | 08a4038 | 1994-06-21 11:44:21 +0000 | [diff] [blame] | 795 | if type(cnf) == StringType: |
Guido van Rossum | 9b68fd9 | 1994-06-23 07:40:14 +0000 | [diff] [blame] | 796 | x = self.tk.split(self._do('itemconfigure', |
| 797 | (tagOrId, '-'+cnf,))) |
| 798 | return (x[0][1:],) + x[1:] |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 799 | self._do('itemconfigure', (tagOrId,) + self._options(cnf)) |
| 800 | def lower(self, *args): |
| 801 | self._do('lower', args) |
| 802 | def move(self, *args): |
| 803 | self._do('move', args) |
| 804 | def postscript(self, cnf={}): |
| 805 | return self._do('postscript', self._options(cnf)) |
| 806 | def tkraise(self, *args): |
| 807 | self._do('raise', args) |
Guido van Rossum | 5e8d372 | 1994-06-20 08:12:01 +0000 | [diff] [blame] | 808 | lift = tkraise |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 809 | def scale(self, *args): |
| 810 | self._do('scale', args) |
| 811 | def scan_mark(self, x, y): |
| 812 | self.tk.call(self._w, 'scan', 'mark', x, y) |
| 813 | def scan_dragto(self, x, y): |
| 814 | self.tk.call(self._w, 'scan', 'dragto', x, y) |
| 815 | def select_adjust(self, tagOrId, index): |
Guido van Rossum | 08a4038 | 1994-06-21 11:44:21 +0000 | [diff] [blame] | 816 | self.tk.call(self._w, 'select', 'adjust', tagOrId, index) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 817 | def select_clear(self): |
| 818 | self.tk.call(self._w, 'select', 'clear') |
| 819 | def select_from(self, tagOrId, index): |
Guido van Rossum | 08a4038 | 1994-06-21 11:44:21 +0000 | [diff] [blame] | 820 | self.tk.call(self._w, 'select', 'from', tagOrId, index) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 821 | def select_item(self): |
| 822 | self.tk.call(self._w, 'select', 'item') |
| 823 | def select_to(self, tagOrId, index): |
Guido van Rossum | 08a4038 | 1994-06-21 11:44:21 +0000 | [diff] [blame] | 824 | self.tk.call(self._w, 'select', 'to', tagOrId, index) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 825 | def type(self, tagOrId): |
Guido van Rossum | 08a4038 | 1994-06-21 11:44:21 +0000 | [diff] [blame] | 826 | return self.tk.call(self._w, 'type', tagOrId) or None |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 827 | def xview(self, index): |
| 828 | self.tk.call(self._w, 'xview', index) |
| 829 | def yview(self, index): |
| 830 | self.tk.call(self._w, 'yview', index) |
| 831 | |
| 832 | class Checkbutton(Widget): |
| 833 | def __init__(self, master=None, cnf={}): |
| 834 | Widget.__init__(self, master, 'checkbutton', cnf) |
| 835 | def deselect(self): |
| 836 | self.tk.call(self._w, 'deselect') |
| 837 | def flash(self): |
| 838 | self.tk.call(self._w, 'flash') |
| 839 | def invoke(self): |
| 840 | self.tk.call(self._w, 'invoke') |
| 841 | def select(self): |
| 842 | self.tk.call(self._w, 'select') |
| 843 | def toggle(self): |
| 844 | self.tk.call(self._w, 'toggle') |
| 845 | |
| 846 | class Entry(Widget): |
| 847 | def __init__(self, master=None, cnf={}): |
| 848 | Widget.__init__(self, master, 'entry', cnf) |
| 849 | def tk_entryBackspace(self): |
| 850 | self.tk.call('tk_entryBackspace', self._w) |
| 851 | def tk_entryBackword(self): |
| 852 | self.tk.call('tk_entryBackword', self._w) |
| 853 | def tk_entrySeeCaret(self): |
| 854 | self.tk.call('tk_entrySeeCaret', self._w) |
| 855 | def delete(self, first, last=None): |
| 856 | self.tk.call(self._w, 'delete', first, last) |
| 857 | def get(self): |
| 858 | return self.tk.call(self._w, 'get') |
| 859 | def icursor(self, index): |
| 860 | self.tk.call(self._w, 'icursor', index) |
| 861 | def index(self, index): |
| 862 | return self.tk.getint(self.tk.call( |
| 863 | self._w, 'index', index)) |
| 864 | def insert(self, index, string): |
| 865 | self.tk.call(self._w, 'insert', index, string) |
| 866 | def scan_mark(self, x): |
| 867 | self.tk.call(self._w, 'scan', 'mark', x) |
| 868 | def scan_dragto(self, x): |
| 869 | self.tk.call(self._w, 'scan', 'dragto', x) |
| 870 | def select_adjust(self, index): |
| 871 | self.tk.call(self._w, 'select', 'adjust', index) |
| 872 | def select_clear(self): |
| 873 | self.tk.call(self._w, 'select', 'clear') |
| 874 | def select_from(self, index): |
| 875 | self.tk.call(self._w, 'select', 'from', index) |
| 876 | def select_to(self, index): |
| 877 | self.tk.call(self._w, 'select', 'to', index) |
| 878 | def select_view(self, index): |
| 879 | self.tk.call(self._w, 'select', 'view', index) |
| 880 | |
| 881 | class Frame(Widget): |
| 882 | def __init__(self, master=None, cnf={}): |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame^] | 883 | cnf = _cnfmerge(cnf) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 884 | extra = () |
| 885 | if cnf.has_key('class'): |
| 886 | extra = ('-class', cnf['class']) |
| 887 | del cnf['class'] |
| 888 | Widget.__init__(self, master, 'frame', cnf, extra) |
| 889 | def tk_menuBar(self, *args): |
| 890 | apply(self.tk.call, ('tk_menuBar', self._w) + args) |
| 891 | |
| 892 | class Label(Widget): |
| 893 | def __init__(self, master=None, cnf={}): |
| 894 | Widget.__init__(self, master, 'label', cnf) |
| 895 | |
| 896 | class Listbox(Widget): |
| 897 | def __init__(self, master=None, cnf={}): |
| 898 | Widget.__init__(self, master, 'listbox', cnf) |
| 899 | def tk_listboxSingleSelect(self): |
| 900 | self.tk.call('tk_listboxSingleSelect', self._w) |
| 901 | def curselection(self): |
| 902 | return self.tk.splitlist(self.tk.call( |
| 903 | self._w, 'curselection')) |
| 904 | def delete(self, first, last=None): |
| 905 | self.tk.call(self._w, 'delete', first, last) |
| 906 | def get(self, index): |
| 907 | return self.tk.call(self._w, 'get', index) |
| 908 | def insert(self, index, *elements): |
| 909 | apply(self.tk.call, |
| 910 | (self._w, 'insert', index) + elements) |
| 911 | def nearest(self, y): |
| 912 | return self.tk.getint(self.tk.call( |
| 913 | self._w, 'nearest', y)) |
| 914 | def scan_mark(self, x, y): |
| 915 | self.tk.call(self._w, 'scan', 'mark', x, y) |
| 916 | def scan_dragto(self, x, y): |
| 917 | self.tk.call(self._w, 'scan', 'dragto', x, y) |
| 918 | def select_adjust(self, index): |
| 919 | self.tk.call(self._w, 'select', 'adjust', index) |
| 920 | def select_clear(self): |
| 921 | self.tk.call(self._w, 'select', 'clear') |
| 922 | def select_from(self, index): |
| 923 | self.tk.call(self._w, 'select', 'from', index) |
| 924 | def select_to(self, index): |
| 925 | self.tk.call(self._w, 'select', 'to', index) |
| 926 | def size(self): |
| 927 | return self.tk.getint(self.tk.call(self._w, 'size')) |
| 928 | def xview(self, index): |
| 929 | self.tk.call(self._w, 'xview', index) |
| 930 | def yview(self, index): |
| 931 | self.tk.call(self._w, 'yview', index) |
| 932 | |
| 933 | class Menu(Widget): |
| 934 | def __init__(self, master=None, cnf={}): |
| 935 | Widget.__init__(self, master, 'menu', cnf) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 936 | def tk_bindForTraversal(self): |
| 937 | self.tk.call('tk_bindForTraversal', self._w) |
| 938 | def tk_mbPost(self): |
| 939 | self.tk.call('tk_mbPost', self._w) |
| 940 | def tk_mbUnpost(self): |
| 941 | self.tk.call('tk_mbUnpost') |
| 942 | def tk_traverseToMenu(self, char): |
| 943 | self.tk.call('tk_traverseToMenu', self._w, char) |
| 944 | def tk_traverseWithinMenu(self, char): |
| 945 | self.tk.call('tk_traverseWithinMenu', self._w, char) |
| 946 | def tk_getMenuButtons(self): |
| 947 | return self.tk.call('tk_getMenuButtons', self._w) |
| 948 | def tk_nextMenu(self, count): |
| 949 | self.tk.call('tk_nextMenu', count) |
| 950 | def tk_nextMenuEntry(self, count): |
| 951 | self.tk.call('tk_nextMenuEntry', count) |
| 952 | def tk_invokeMenu(self): |
| 953 | self.tk.call('tk_invokeMenu', self._w) |
| 954 | def tk_firstMenu(self): |
| 955 | self.tk.call('tk_firstMenu', self._w) |
| 956 | def tk_mbButtonDown(self): |
| 957 | self.tk.call('tk_mbButtonDown', self._w) |
| 958 | def activate(self, index): |
| 959 | self.tk.call(self._w, 'activate', index) |
| 960 | def add(self, itemType, cnf={}): |
| 961 | apply(self.tk.call, (self._w, 'add', itemType) |
| 962 | + self._options(cnf)) |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 963 | def add_cascade(self, cnf={}): |
| 964 | self.add('cascade', cnf) |
| 965 | def add_checkbutton(self, cnf={}): |
| 966 | self.add('checkbutton', cnf) |
| 967 | def add_command(self, cnf={}): |
| 968 | self.add('command', cnf) |
| 969 | def add_radiobutton(self, cnf={}): |
| 970 | self.add('radiobutton', cnf) |
| 971 | def add_separator(self, cnf={}): |
| 972 | self.add('separator', cnf) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 973 | def delete(self, index1, index2=None): |
| 974 | self.tk.call(self._w, 'delete', index1, index2) |
| 975 | def entryconfig(self, index, cnf={}): |
| 976 | apply(self.tk.call, (self._w, 'entryconfigure', index) |
| 977 | + self._options(cnf)) |
| 978 | def index(self, index): |
Guido van Rossum | 535cf0c | 1994-06-27 07:55:59 +0000 | [diff] [blame] | 979 | i = self.tk.call(self._w, 'index', index) |
| 980 | if i == 'none': return None |
| 981 | return self.tk.getint(i) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 982 | def invoke(self, index): |
| 983 | return self.tk.call(self._w, 'invoke', index) |
| 984 | def post(self, x, y): |
| 985 | self.tk.call(self._w, 'post', x, y) |
| 986 | def unpost(self): |
| 987 | self.tk.call(self._w, 'unpost') |
| 988 | def yposition(self, index): |
| 989 | return self.tk.getint(self.tk.call( |
| 990 | self._w, 'yposition', index)) |
| 991 | |
| 992 | class Menubutton(Widget): |
| 993 | def __init__(self, master=None, cnf={}): |
| 994 | Widget.__init__(self, master, 'menubutton', cnf) |
| 995 | |
| 996 | class Message(Widget): |
| 997 | def __init__(self, master=None, cnf={}): |
| 998 | Widget.__init__(self, master, 'message', cnf) |
| 999 | |
| 1000 | class Radiobutton(Widget): |
| 1001 | def __init__(self, master=None, cnf={}): |
| 1002 | Widget.__init__(self, master, 'radiobutton', cnf) |
| 1003 | def deselect(self): |
| 1004 | self.tk.call(self._w, 'deselect') |
| 1005 | def flash(self): |
| 1006 | self.tk.call(self._w, 'flash') |
| 1007 | def invoke(self): |
| 1008 | self.tk.call(self._w, 'invoke') |
| 1009 | def select(self): |
| 1010 | self.tk.call(self._w, 'select') |
| 1011 | |
| 1012 | class Scale(Widget): |
| 1013 | def __init__(self, master=None, cnf={}): |
| 1014 | Widget.__init__(self, master, 'scale', cnf) |
| 1015 | def get(self): |
| 1016 | return self.tk.getint(self.tk.call(self._w, 'get')) |
| 1017 | def set(self, value): |
| 1018 | self.tk.call(self._w, 'set', value) |
| 1019 | |
| 1020 | class Scrollbar(Widget): |
| 1021 | def __init__(self, master=None, cnf={}): |
| 1022 | Widget.__init__(self, master, 'scrollbar', cnf) |
| 1023 | def get(self): |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 1024 | return self._getints(self.tk.call(self._w, 'get')) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1025 | def set(self, totalUnits, windowUnits, firstUnit, lastUnit): |
| 1026 | self.tk.call(self._w, 'set', |
| 1027 | totalUnits, windowUnits, firstUnit, lastUnit) |
| 1028 | |
| 1029 | class Text(Widget): |
| 1030 | def __init__(self, master=None, cnf={}): |
| 1031 | Widget.__init__(self, master, 'text', cnf) |
| 1032 | def tk_textSelectTo(self, index): |
| 1033 | self.tk.call('tk_textSelectTo', self._w, index) |
| 1034 | def tk_textBackspace(self): |
| 1035 | self.tk.call('tk_textBackspace', self._w) |
| 1036 | def tk_textIndexCloser(self, a, b, c): |
| 1037 | self.tk.call('tk_textIndexCloser', self._w, a, b, c) |
| 1038 | def tk_textResetAnchor(self, index): |
| 1039 | self.tk.call('tk_textResetAnchor', self._w, index) |
| 1040 | def compare(self, index1, op, index2): |
| 1041 | return self.tk.getboolean(self.tk.call( |
| 1042 | self._w, 'compare', index1, op, index2)) |
| 1043 | def debug(self, boolean=None): |
| 1044 | return self.tk.getboolean(self.tk.call( |
| 1045 | self._w, 'debug', boolean)) |
| 1046 | def delete(self, index1, index2=None): |
| 1047 | self.tk.call(self._w, 'delete', index1, index2) |
| 1048 | def get(self, index1, index2=None): |
| 1049 | return self.tk.call(self._w, 'get', index1, index2) |
| 1050 | def index(self, index): |
| 1051 | return self.tk.call(self._w, 'index', index) |
| 1052 | def insert(self, index, chars): |
| 1053 | self.tk.call(self._w, 'insert', index, chars) |
| 1054 | def mark_names(self): |
| 1055 | return self.tk.splitlist(self.tk.call( |
| 1056 | self._w, 'mark', 'names')) |
| 1057 | def mark_set(self, markName, index): |
| 1058 | self.tk.call(self._w, 'mark', 'set', markName, index) |
| 1059 | def mark_unset(self, markNames): |
| 1060 | apply(self.tk.call, (self._w, 'mark', 'unset') + markNames) |
| 1061 | def scan_mark(self, y): |
| 1062 | self.tk.call(self._w, 'scan', 'mark', y) |
| 1063 | def scan_dragto(self, y): |
| 1064 | self.tk.call(self._w, 'scan', 'dragto', y) |
| 1065 | def tag_add(self, tagName, index1, index2=None): |
| 1066 | self.tk.call( |
| 1067 | self._w, 'tag', 'add', tagName, index1, index2) |
| 1068 | def tag_bind(self, tagName, sequence, func, add=''): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1069 | if add: add='+' |
Guido van Rossum | 45853db | 1994-06-20 12:19:19 +0000 | [diff] [blame] | 1070 | name = self._register(func, self._substitute) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1071 | self.tk.call(self._w, 'tag', 'bind', |
| 1072 | tagName, sequence, |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 1073 | (add + name,) + self._subst_format) |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1074 | def tag_config(self, tagName, cnf={}): |
| 1075 | apply(self.tk.call, |
| 1076 | (self._w, 'tag', 'configure', tagName) |
| 1077 | + self._options(cnf)) |
Guido van Rossum | 2dcf529 | 1994-07-06 09:23:20 +0000 | [diff] [blame^] | 1078 | def tag_delete(self, *tagNames): |
Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame] | 1079 | apply(self.tk.call, (self._w, 'tag', 'delete') |
| 1080 | + tagNames) |
| 1081 | def tag_lower(self, tagName, belowThis=None): |
| 1082 | self.tk.call(self._w, 'tag', 'lower', |
| 1083 | tagName, belowThis) |
| 1084 | def tag_names(self, index=None): |
| 1085 | return self.tk.splitlist( |
| 1086 | self.tk.call(self._w, 'tag', 'names', index)) |
| 1087 | def tag_nextrange(self, tagName, index1, index2=None): |
| 1088 | return self.tk.splitlist(self.tk.call( |
| 1089 | self._w, 'tag', 'nextrange', index1, index2)) |
| 1090 | def tag_raise(self, tagName, aboveThis=None): |
| 1091 | self.tk.call( |
| 1092 | self._w, 'tag', 'raise', tagName, aboveThis) |
| 1093 | def tag_ranges(self, tagName): |
| 1094 | return self.tk.splitlist(self.tk.call( |
| 1095 | self._w, 'tag', 'ranges', tagName)) |
| 1096 | def tag_remove(self, tagName, index1, index2=None): |
| 1097 | self.tk.call( |
| 1098 | self._w, 'tag', 'remove', index1, index2) |
| 1099 | def yview(self, what): |
| 1100 | self.tk.call(self._w, 'yview', what) |
| 1101 | def yview_pickplace(self, what): |
| 1102 | self.tk.call(self._w, 'yview', '-pickplace', what) |
| 1103 | |
Guido van Rossum | aec5dc9 | 1994-06-27 07:55:12 +0000 | [diff] [blame] | 1104 | ###################################################################### |
| 1105 | # Extensions: |
| 1106 | |
| 1107 | class Studbutton(Button): |
| 1108 | def __init__(self, master=None, cnf={}): |
| 1109 | Widget.__init__(self, master, 'studbutton', cnf) |
| 1110 | self.bind('<Any-Enter>', self.tk_butEnter) |
| 1111 | self.bind('<Any-Leave>', self.tk_butLeave) |
| 1112 | self.bind('<1>', self.tk_butDown) |
| 1113 | self.bind('<ButtonRelease-1>', self.tk_butUp) |
| 1114 | |
| 1115 | class Tributton(Button): |
| 1116 | def __init__(self, master=None, cnf={}): |
| 1117 | Widget.__init__(self, master, 'tributton', cnf) |
| 1118 | self.bind('<Any-Enter>', self.tk_butEnter) |
| 1119 | self.bind('<Any-Leave>', self.tk_butLeave) |
| 1120 | self.bind('<1>', self.tk_butDown) |
| 1121 | self.bind('<ButtonRelease-1>', self.tk_butUp) |
| 1122 | |