Tk模块之Text()

class Text(Widget, XView, YView):
    """Text类能够以不同的形式展示文本"""
    def __init__(self, master=None, cnf={}, **kw):
         ""用父MASTER构造一个文本小部件。""
     
        STANDARD OPTIONS(标准配置)

            background, borderwidth, cursor,
            背景,边界宽度,游标
            -----------------------------------
            exportselection, font, foreground,
            到处所选对象,字体,前台
            -----------------------------------

            highlightbackground, highlightcolor,
            高亮背景,高亮颜色
            -----------------------------------
            
            highlightthickness, insertbackground,
            高光厚度,插入背景
            -----------------------------------
            insertborderwidth, insertofftime,
            插入边界宽度,插入离线时间
            -----------------------------------
            insertontime, insertwidth, padx, pady,
            插入上线时间,插入宽度,填充x轴,填充y轴
            -----------------------------------
            relief, selectbackground,
            清除,选择背景
            -----------------------------------
            selectborderwidth, selectforeground,
            选择边界宽度,选择前台
            -----------------------------------
            setgrid, takefocus,
            设置布局,设置焦点
            -----------------------------------
            xscrollcommand, yscrollcommand,
            x轴滚动命令,y轴滚动命令
            -----------------------------------

        WIDGET-特殊配置

            autoseparators, height, maxundo,
            自动分离器,高度,***
            spacing1, spacing2, spacing3,
            空格1,空格2,空格3
            state, tabs, undo, width, wrap,
            

        """
        Widget.__init__(self, master, 'text', cnf, kw)
    def bbox(self, index):
        """ 返回一个包括(x,y,宽度,高度)的元组,这个元组给出在字符在给定索引处可视部分的边界框"""
       
        return self._getints(
                self.tk.call(self._w, 'bbox', index)) or None
    def compare(self, index1, op, index2):
        """Return whether between index INDEX1 and index INDEX2 the
        relation OP is satisfied. OP is one of <, <=, ==, >=, >, or !=."""
        return self.tk.getboolean(self.tk.call(
            self._w, 'compare', index1, op, index2))
            
    def count(self, index1, index2, *args): # new in Tk 8.5 
        """
         计算出两个索引之间相关联的事物的数量,如果索引1在索引2之后,结果将会是负数
         对每一个可能的参数都将进行这样的操作
         
        实际计算的项目取决于args给出的选项。结果是一个整数列表,
        其中一个表示给出的每个计数选项的结果。
        有效的计数选项有"chars""displaychars""displayindices""displaylines""indices""lines""xpixels""ypixels"。
        另外还有一个可能的选项“update”,如果给出该选项,
        则所有后续选项都将确保重新计算任何可能过期的信息。"""
        args = ['-%s' % arg for arg in args if not arg.startswith('-')]
        args += [index1, index2]
        res = self.tk.call(self._w, 'count', *args) or None
        if res is not None and len(args) <= 3:
            return (res, )
        else:
            return res
-------------------------------------------------------------------------------


    def debug(self, boolean=None):
        """根据布尔值在文本小部件中打开B-Tree的内部一致性检查."""
        if boolean is None:
            return self.tk.getboolean(self.tk.call(self._w, 'debug'))
        self.tk.call(self._w, 'debug', boolean)
-------------------------------------------------------------------------------        
    def delete(self, index1, index2=None):
        """删除INDEX1和INDEX2之间的字符 (not included)."""
        self.tk.call(self._w, 'delete', index1, index2)
        
-------------------------------------------------------------------------------        
    def dlineinfo(self, index):
        """返回元组(x,y,width,height,baseline),
        给出包含INDEX字符的行中可见部分的边界框和基线位置。"""
        return self._getints(self.tk.call(self._w, 'dlineinfo', index))
                
-------------------------------------------------------------------------------        
    def dump(self, index1, index2=None, command=None, **kw):
        """返回小部件在index1和index2之间的内容。
        根据关键字参数过滤返回的内容的类型;
        如果给定'all''image''mark''tag''text',或'window'并为真
        ,则返回相应的项。结果是一个三元组列表(键、值、索引)。如果所有关键字
        都不为真,则默认使用'all'。如果给出了'command'参数,它将为三元组列表
        中的每个元素调用一次,每个三元组的值作为函数的参数。在本例中,不返回列表。"""
        args = []
        func_name = None
        result = None
        if not command:
            # Never call the dump command without the -command flag, since the
            # output could involve Tcl quoting and would be a pain to parse
            # right. Instead just set the command to build a list of triples
            # as if we had done the parsing.
            result = []
            def append_triple(key, value, index, result=result):
                result.append((key, value, index))
            command = append_triple
        try:
            if not isinstance(command, str):
                func_name = command = self._register(command)
            args += ["-command", command]
            for key in kw:
                if kw[key]: args.append("-" + key)
            args.append(index1)
            if index2:
                args.append(index2)
            self.tk.call(self._w, "dump", *args)
            return result
        finally:
            if func_name:
                self.deletecommand(func_name)
        
-------------------------------------------------------------------------------        
    ## new in tk8.4
    def edit(self, *args):
        """内部方法该方法控制撤销机制和修改后的标志。
        命令的确切行为取决于edit参数后面的option参数。
        目前支持以下命令形式:编辑修改、编辑重做、编辑重置、
        编辑分隔符和编辑撤销

        """
        return self.tk.call(self._w, 'edit', *args)
        
-------------------------------------------------------------------------------        
    def edit_modified(self, arg=None):
        """如果未指定arg,则返回小部件的修改标志。
        用户可以通过插入、删除、编辑撤销和编辑重做命令或设置或清除修改标志。
        如果指定了boolean,则将小部件的modified标志设置为arg。
        """
        return self.edit("modified", arg)
        
-------------------------------------------------------------------------------        
    def edit_redo(self):
        """重做最后一次未完成的编辑当撤销选项为true时,
        重新应用最后一次未完成的编辑,前提是此后没有进行其他编辑。
        当重做堆栈为空时生成一个错误。当undo选项为false时,不执行任何操作。
        """
        return self.edit("redo")
        
-------------------------------------------------------------------------------        
    def edit_reset(self):
        """清除撤销和重做堆栈
        """
        return self.edit("reset")
        
-------------------------------------------------------------------------------        
    def edit_separator(self):
        """在撤消堆栈上插入分隔符(边界)。当撤销选项为false时什么也不做
        """
        return self.edit("separator")
        
-------------------------------------------------------------------------------        
    def edit_undo(self):
        """
        撤销最近一次的编辑行为

        """
        如果撤销参数为真,那么一个编辑行为将被定义为所有的插入和删除命令,
        并且这些命令已经被记录在两个分离器中的栈堆中。当撤销栈堆为空时将报错!
        当撤销参数为假时不执行任何操作
        return self.edit("undo")
        
-------------------------------------------------------------------------------        
    def get(self, index1, index2=None):
        """从index1和index2处返回文本"""
        return self.tk.call(self._w, 'get', index1, index2)
    # (Image commands are new in 8.0)
            
-------------------------------------------------------------------------------        
    def image_cget(self, index, option):
        """ 返回在index处内嵌图像的参数值"""
        if option[:1] != "-":
            option = "-" + option
        if option[-1:] == "_":
            option = option[:-1]
        return self.tk.call(self._w, "image", "cget", index, option)
                
-------------------------------------------------------------------------------        
    def image_configure(self, index, cnf=None, **kw):
        """在index处配置一个图像."""
        return self._configure(('image', 'configure', index), cnf, kw)
                        
-------------------------------------------------------------------------------  
    def image_create(self, index, cnf={}, **kw):
        """在index处创建一个嵌入图像"""
        return self.tk.call(
                 self._w, "image", "create", index,
                 *self._options(cnf, kw))
                                 
-------------------------------------------------------------------------------  
    def image_names(self):
        """在这个工具中返回所有嵌入图像的名字"""
        return self.tk.call(self._w, "image", "names")
                        
-------------------------------------------------------------------------------  
    def index(self, index):
        """返回表单的索引值。字符的索引"""
        return str(self.tk.call(self._w, 'index', index))
                                
-------------------------------------------------------------------------------  
    def insert(self, index, chars, *args):
        """ 在index的处的字符前插入一个字符。在ARGS中将会给出一个新增的标签。新增的字符和标签可以跟随ARGS。"""
       
        self.tk.call((self._w, 'insert', index, chars) + args)
                                      
-------------------------------------------------------------------------------
    def mark_gravity(self, markName, direction=None):
        """Change the gravity of a mark MARKNAME to DIRECTION (LEFT or RIGHT).
        Return the current value if None is given for DIRECTION."""
        return self.tk.call(
            (self._w, 'mark', 'gravity', markName, direction))
                                            
-------------------------------------------------------------------------------
    def mark_names(self):
        """返回所有标号/记号的名字."""
        return self.tk.splitlist(self.tk.call(
            self._w, 'mark', 'names'))
                                            
-------------------------------------------------------------------------------
    def mark_set(self, markName, index):
        """在index处的字符前,给标号设置标号名"""
        self.tk.call(self._w, 'mark', 'set', markName, index)
                                        
-------------------------------------------------------------------------------
    def mark_unset(self, *markNames):
        """Delete all marks in MARKNAMES."""
        self.tk.call((self._w, 'mark', 'unset') + markNames)
                                        
-------------------------------------------------------------------------------
    def mark_next(self, index):
        """返回index之后的下个标号的名字"""
        return self.tk.call(self._w, 'mark', 'next', index) or None
                                        
-------------------------------------------------------------------------------
    def mark_previous(self, index):
        """返回在index前面的以前的标号的名字"""
        return self.tk.call(self._w, 'mark', 'previous', index) or None
                                        
-------------------------------------------------------------------------------
    def peer_create(self, newPathName, cnf={}, **kw): # new in Tk 8.5
        """用给定的newPathName创建一个同级的文本工具和任何可选的标准配置选项。
        默认统计文本工具和它的父级工具一样有着相同的起始线和终止线。
        但是这些可以被标准配置参数重写"""
        
        self.tk.call(self._w, 'peer', 'create', newPathName,
            *self._options(cnf, kw))
                                                    
-------------------------------------------------------------------------------
    def peer_names(self): # new in Tk 8.5
        """返回这个工具的同级工具的列表,不包括这个工具本身"""
        return self.tk.splitlist(self.tk.call(self._w, 'peer', 'names'))
                                                
-------------------------------------------------------------------------------
    def replace(self, index1, index2, chars, *args): # new in Tk 8.5
        """Replaces the range of characters between index1 and index2 with
        the given characters and tags specified by args.用给定的字符和被args设定的标签取代index1和index2之间的字符串的范围

        See the method insert for some more information about args, and the
        method delete for information about the indices."""
        self.tk.call(self._w, 'replace', index1, index2, chars, *args)                                        
-------------------------------------------------------------------------------
    def scan_mark(self, x, y):
        """记住当前x和y的坐标"""
        self.tk.call(self._w, 'scan', 'mark', x, y)
                                                
-------------------------------------------------------------------------------
    def scan_dragto(self, x, y):
        """把text的视图调整为在scan——mark中给处的x和y的坐标的差异的十倍"""
        self.tk.call(self._w, 'scan', 'dragto', x, y)
                                                
-------------------------------------------------------------------------------
    def search(self, pattern, index, stopindex=None,
           forwards=None, backwards=None, exact=None,
           regexp=None, nocase=None, count=None, elide=None):
        """在INDEX中搜索所有的PATTERN直到STOPINDEX为止。
        返回匹配结果的第一个字符的index或者是一个空的字符串"""
        args = [self._w, 'search']
        if forwards: args.append('-forwards')
        if backwards: args.append('-backwards')
        if exact: args.append('-exact')
        if regexp: args.append('-regexp')
        if nocase: args.append('-nocase')
        if elide: args.append('-elide')
        if count: args.append('-count'); args.append(count)
        if pattern and pattern[0] == '-': args.append('--')
        args.append(pattern)
        args.append(index)
        if stopindex: args.append(stopindex)
        return str(self.tk.call(tuple(args)))
                                                
-------------------------------------------------------------------------------
    def see(self, index):
        """滚动使INDEX处的字符可见"""
        self.tk.call(self._w, 'see', index)
                                                
-------------------------------------------------------------------------------
    def tag_add(self, tagName, index1, *args):
        """在ARGS中为INDEX1和index2之间的所有字符添加tag TAGNAME。
        在ARGS中可能会有额外的索引对。"""
        self.tk.call(
            (self._w, 'tag', 'add', tagName, index1) + args)
                                                    
-------------------------------------------------------------------------------
    def tag_unbind(self, tagName, sequence, funcid=None):
        """为事件序列的所有带有TAGNAME的字符解除绑定,该函数由FUNCID标识."""
        self.tk.call(self._w, 'tag', 'bind', tagName, sequence, '')
        if funcid:
            self.deletecommand(funcid)
                                                    
-------------------------------------------------------------------------------
    def tag_bind(self, tagName, sequence, func, add=None):
        """Bind to all characters with TAGNAME at event SEQUENCE a call to function FUNC.

        An additional boolean parameter ADD specifies whether FUNC will be
        called additionally to the other bound function or whether it will
        replace the previous function. See bind for the return value."""
        return self._bind((self._w, 'tag', 'bind', tagName),
                  sequence, func, add)
                                                          
-------------------------------------------------------------------------------
    def tag_cget(self, tagName, option):
        """Return the value of OPTION for tag TAGNAME.为了tagName标签返回option的值"""
        if option[:1] != '-':
            option = '-' + option
        if option[-1:] == '_':
            option = option[:-1]
        return self.tk.call(self._w, 'tag', 'cget', tagName, option)
                                                
-------------------------------------------------------------------------------
    def tag_configure(self, tagName, cnf=None, **kw):
        """配置一个tagName的标签"""
        return self._configure(('tag', 'configure', tagName), cnf, kw)
    tag_config = tag_configure
                                            
-------------------------------------------------------------------------------
    def tag_delete(self, *tagNames):
        """在tageNames中删除所有的标签"""
        self.tk.call((self._w, 'tag', 'delete') + tagNames)
                                                
-------------------------------------------------------------------------------
    def tag_lower(self, tagName, belowThis=None):
        """Change the priority of tag TAGNAME such that it is lower
        than the priority of BELOWTHIS.改变tagname这个标签的优先级使其低于belowthis"""
        self.tk.call(self._w, 'tag', 'lower', tagName, belowThis)
                                                
-------------------------------------------------------------------------------
    def tag_names(self, index=None):
        """返回所有标签名字的列表"""
        return self.tk.splitlist(
            self.tk.call(self._w, 'tag', 'names', index))
                                                    
-------------------------------------------------------------------------------
    def tag_nextrange(self, tagName, index1, index2=None):
        """返回INDEX1和INDEX2之间的第一个字符序列的起始和结束索引的列表,这些字符都具有TAGNAME标记。从INDEX1向前搜索文本。"""
        return self.tk.splitlist(self.tk.call(
            self._w, 'tag', 'nextrange', tagName, index1, index2))
                                                    
-------------------------------------------------------------------------------
    def tag_prevrange(self, tagName, index1, index2=None):
        """返回INDEX1和INDEX2之间的第一个字符序列的起始和结束索引的列表,
        这些字符都具有TAGNAME标记。从INDEX1向后搜索文本。"""
        return self.tk.splitlist(self.tk.call(
            self._w, 'tag', 'prevrange', tagName, index1, index2))
                                                    
-------------------------------------------------------------------------------
    def tag_raise(self, tagName, aboveThis=None):
        """修改标签TAGNAME的优先级,使其高于ABOVETHIS的优先级."""
        self.tk.call(
            self._w, 'tag', 'raise', tagName, aboveThis)
                                                    
-------------------------------------------------------------------------------
    def tag_ranges(self, tagName):
        """返回具有tagname标签的文本的范围的列表"""
        return self.tk.splitlist(self.tk.call(
            self._w, 'tag', 'ranges', tagName))
                                                    
-------------------------------------------------------------------------------
    def tag_remove(self, tagName, index1, index2=None):
        """从index1和index2所有的字符中间移除掉tagname"""
        self.tk.call(
            self._w, 'tag', 'remove', tagName, index1, index2)
                                                    
-------------------------------------------------------------------------------
    def window_cget(self, index, option):
        """返回一个在index处嵌入的窗口option的值"""
        if option[:1] != '-':
            option = '-' + option
        if option[-1:] == '_':
            option = option[:-1]
        return self.tk.call(self._w, 'window', 'cget', index, option)
                                                
-------------------------------------------------------------------------------
    def window_configure(self, index, cnf=None, **kw):
        """Configure an embedded window at INDEX."""
        return self._configure(('window', 'configure', index), cnf, kw)
    window_config = window_configure
                                            
-------------------------------------------------------------------------------
    def window_create(self, index, cnf={}, **kw):
        """在index处创建一个窗口"""
        self.tk.call(
              (self._w, 'window', 'create', index)
              + self._options(cnf, kw))
                                        
-------------------------------------------------------------------------------
    def window_names(self):
        """在这个工具中返回所有嵌入工具的名字"""
        return self.tk.splitlist(
            self.tk.call(self._w, 'window', 'names'))
                                                    
-------------------------------------------------------------------------------
    def yview_pickplace(self, *what):
        """Obsolete function, use see."""
        self.tk.call((self._w, 'yview', '-pickplace') + what)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

山河锦绣放眼好风光

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值