📄 tkinter.py
字号:
return getint( self.tk.call('winfo', 'screenheight', self._w)) def winfo_screenmmheight(self): return getint( self.tk.call('winfo', 'screenmmheight', self._w)) def winfo_screenmmwidth(self): return getint( self.tk.call('winfo', 'screenmmwidth', self._w)) def winfo_screenvisual(self): return self.tk.call('winfo', 'screenvisual', self._w) def winfo_screenwidth(self): return getint( self.tk.call('winfo', 'screenwidth', self._w)) def winfo_server(self): return self.tk.call('winfo', 'server', self._w) def winfo_toplevel(self): return self._nametowidget(self.tk.call( 'winfo', 'toplevel', self._w)) def winfo_viewable(self): return getint( self.tk.call('winfo', 'viewable', self._w)) def winfo_visual(self): return self.tk.call('winfo', 'visual', self._w) def winfo_visualid(self): return self.tk.call('winfo', 'visualid', self._w) def winfo_visualsavailable(self, includeids=0): data = self.tk.split( self.tk.call('winfo', 'visualsavailable', self._w, includeids and 'includeids' or None)) return map(self.__winfo_parseitem, data) def __winfo_parseitem(self, t): return t[:1] + tuple(map(self.__winfo_getint, t[1:])) def __winfo_getint(self, x): return _string.atoi(x, 0) def winfo_vrootheight(self): return getint( self.tk.call('winfo', 'vrootheight', self._w)) def winfo_vrootwidth(self): return getint( self.tk.call('winfo', 'vrootwidth', self._w)) def winfo_vrootx(self): return getint( self.tk.call('winfo', 'vrootx', self._w)) def winfo_vrooty(self): return getint( self.tk.call('winfo', 'vrooty', self._w)) def winfo_width(self): return getint( self.tk.call('winfo', 'width', self._w)) def winfo_x(self): return getint( self.tk.call('winfo', 'x', self._w)) def winfo_y(self): return getint( self.tk.call('winfo', 'y', self._w)) def update(self): self.tk.call('update') def update_idletasks(self): self.tk.call('update', 'idletasks') def bindtags(self, tagList=None): if tagList is None: return self.tk.splitlist( self.tk.call('bindtags', self._w)) else: self.tk.call('bindtags', self._w, tagList) def _bind(self, what, sequence, func, add, needcleanup=1): if type(func) is StringType: self.tk.call(what + (sequence, func)) elif func: funcid = self._register(func, self._substitute, needcleanup) cmd = ('%sif {"[%s %s]" == "break"} break\n' % (add and '+' or '', funcid, _string.join(self._subst_format))) self.tk.call(what + (sequence, cmd)) return funcid elif sequence: return self.tk.call(what + (sequence,)) else: return self.tk.splitlist(self.tk.call(what)) def bind(self, sequence=None, func=None, add=None): return self._bind(('bind', self._w), sequence, func, add) def unbind(self, sequence, funcid=None): self.tk.call('bind', self._w, sequence, '') if funcid: self.deletecommand(funcid) def bind_all(self, sequence=None, func=None, add=None): return self._bind(('bind', 'all'), sequence, func, add, 0) def unbind_all(self, sequence): self.tk.call('bind', 'all' , sequence, '') def bind_class(self, className, sequence=None, func=None, add=None): return self._bind(('bind', className), sequence, func, add, 0) def unbind_class(self, className, sequence): self.tk.call('bind', className , sequence, '') def mainloop(self, n=0): self.tk.mainloop(n) def quit(self): self.tk.quit() def _getints(self, string): if string: return tuple(map(getint, self.tk.splitlist(string))) def _getdoubles(self, string): if string: return tuple(map(getdouble, self.tk.splitlist(string))) def _getboolean(self, string): if string: return self.tk.getboolean(string) def _displayof(self, displayof): if displayof: return ('-displayof', displayof) if displayof is None: return ('-displayof', self._w) return () def _options(self, cnf, kw = None): if kw: cnf = _cnfmerge((cnf, kw)) else: cnf = _cnfmerge(cnf) res = () for k, v in cnf.items(): if v is not None: if k[-1] == '_': k = k[:-1] if callable(v): v = self._register(v) res = res + ('-'+k, v) return res def nametowidget(self, name): w = self if name[0] == '.': w = w._root() name = name[1:] find = _string.find while name: i = find(name, '.') if i >= 0: name, tail = name[:i], name[i+1:] else: tail = '' w = w.children[name] name = tail return w _nametowidget = nametowidget def _register(self, func, subst=None, needcleanup=1): f = CallWrapper(func, subst, self).__call__ name = `id(f)` try: func = func.im_func except AttributeError: pass try: name = name + func.__name__ except AttributeError: pass self.tk.createcommand(name, f) if needcleanup: if self._tclCommands is None: self._tclCommands = [] self._tclCommands.append(name) #print '+ Tkinter created command', name return name register = _register def _root(self): w = self while w.master: w = w.master return w _subst_format = ('%#', '%b', '%f', '%h', '%k', '%s', '%t', '%w', '%x', '%y', '%A', '%E', '%K', '%N', '%W', '%T', '%X', '%Y') def _substitute(self, *args): if len(args) != len(self._subst_format): return args getboolean = self.tk.getboolean getint = int nsign, b, f, h, k, s, t, w, x, y, A, E, K, N, W, T, X, Y = args # Missing: (a, c, d, m, o, v, B, R) e = Event() e.serial = getint(nsign) e.num = getint(b) try: e.focus = getboolean(f) except TclError: pass e.height = getint(h) e.keycode = getint(k) # For Visibility events, event state is a string and # not an integer: try: e.state = getint(s) except ValueError: e.state = s e.time = getint(t) e.width = getint(w) e.x = getint(x) e.y = getint(y) e.char = A try: e.send_event = getboolean(E) except TclError: pass e.keysym = K e.keysym_num = getint(N) e.type = T try: e.widget = self._nametowidget(W) except KeyError: e.widget = W e.x_root = getint(X) e.y_root = getint(Y) return (e,) def _report_exception(self): import sys exc, val, tb = sys.exc_type, sys.exc_value, sys.exc_traceback root = self._root() root.report_callback_exception(exc, val, tb) # These used to be defined in Widget: def configure(self, cnf=None, **kw): # XXX ought to generalize this so tag_config etc. can use it if kw: cnf = _cnfmerge((cnf, kw)) elif cnf: cnf = _cnfmerge(cnf) if cnf is None: cnf = {} for x in self.tk.split( self.tk.call(self._w, 'configure')): cnf[x[0][1:]] = (x[0][1:],) + x[1:] return cnf if type(cnf) is StringType: x = self.tk.split(self.tk.call( self._w, 'configure', '-'+cnf)) return (x[0][1:],) + x[1:] self.tk.call((self._w, 'configure') + self._options(cnf)) config = configure def cget(self, key): return self.tk.call(self._w, 'cget', '-' + key) __getitem__ = cget def __setitem__(self, key, value): self.configure({key: value}) def keys(self): return map(lambda x: x[0][1:], self.tk.split(self.tk.call(self._w, 'configure'))) def __str__(self): return self._w # Pack methods that apply to the master _noarg_ = ['_noarg_'] def pack_propagate(self, flag=_noarg_): if flag is Misc._noarg_: return self._getboolean(self.tk.call( 'pack', 'propagate', self._w)) else: self.tk.call('pack', 'propagate', self._w, flag) propagate = pack_propagate def pack_slaves(self): return map(self._nametowidget, self.tk.splitlist( self.tk.call('pack', 'slaves', self._w))) slaves = pack_slaves # Place method that applies to the master def place_slaves(self): return map(self._nametowidget, self.tk.splitlist( self.tk.call( 'place', 'slaves', self._w))) # Grid methods that apply to the master def grid_bbox(self, column=None, row=None, col2=None, row2=None): args = ('grid', 'bbox', self._w) if column is not None and row is not None: args = args + (column, row) if col2 is not None and row2 is not None: args = args + (col2, row2) return self._getints(apply(self.tk.call, args)) or None bbox = grid_bbox def _grid_configure(self, command, index, cnf, kw): if type(cnf) is StringType and not kw: if cnf[-1:] == '_': cnf = cnf[:-1] if cnf[:1] != '-': cnf = '-'+cnf options = (cnf,) else: options = self._options(cnf, kw) if not options: res = self.tk.call('grid', command, self._w, index) words = self.tk.splitlist(res) dict = {} for i in range(0, len(words), 2): key = words[i][1:] value = words[i+1] if not value: value = None elif '.' in value: value = getdouble(value) else: value = getint(value) dict[key] = value return dict res = self.tk.call( ('grid', command, self._w, index) + options) if len(options) == 1: if not res: return None # In Tk 7.5, -width can be a float if '.' in res: return getdouble(res) return getint(res) def grid_columnconfigure(self, index, cnf={}, **kw): return self._grid_configure('columnconfigure', index, cnf, kw) columnconfigure = grid_columnconfigure def grid_propagate(self, flag=_noarg_): if flag is Misc._noarg_: return self._getboolean(self.tk.call( 'grid', 'propagate', self._w)) else: self.tk.call('grid', 'propagate', self._w, flag) def grid_rowconfigure(self, index, cnf={}, **kw): return self._grid_configure('rowconfigure', index, cnf, kw) rowconfigure = grid_rowconfigure def grid_size(self): return self._getints( self.tk.call('grid', 'size', self._w)) or None size = grid_size def grid_slaves(self, row=None, column=None): args = () if row is not None: args = args + ('-row', row) if column is not None: args = args + ('-column', column) return map(self._nametowidget, self.tk.splitlist(self.tk.call( ('grid', 'slaves', self._w) + args))) # Support for the "event" command, new in Tk 4.2. # By Case Roole. def event_add(self, virtual, *sequences): args = ('event', 'add', virtual) + sequences self.tk.call(args) def event_delete(self, virtual, *sequences): args = ('event', 'delete', virtual) + sequences self.tk.call(args) def event_generate(self, sequence, **kw): args = ('event', 'generate', self._w, sequence) for k, v in kw.items(): args = args + ('-%s' % k, str(v)) self.tk.call(args) def event_info(self, virtual=None): return self.tk.splitlist( self.tk.call('event', 'info', virtual)) # Image related commands def image_names(self): return self.tk.call('image', 'names') def image_types(self): return self.tk.call('image', 'types')class CallWrapper: def __init__(self, func, subst, widget): self.func = func self.subst = subst self.widget = widget def __call__(self, *args): try: if self.subst: args = apply(self.subst, args) return apply(self.func, args) except SystemExit, msg: raise SystemExit, msg except: self.widget._report_exception()class Wm: def wm_aspect(self, minNumer=None, minDenom=None, maxNumer=None, maxDenom=None): return self._getints( self.tk.call('wm', 'aspect', self._w, minNumer, minDenom, maxNumer, maxDenom)) aspect = wm_aspect def wm_client(self, name=None): return self.tk.call('wm', 'client', self._w, name) client = wm_client def wm_colormapwindows(self, *wlist): if len(wlist) > 1: wlist = (wlist,) # Tk needs a list of windows here args = ('wm', 'colormapwindows', self._w) + wlist return map(self._nametowidget, self.tk.call(args)) colormapwindows = wm_colormapwindows def wm_command(self, value=None): return self.tk.call('wm', 'command', self._w, value)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -