【问题标题】:Scroll to text in Tkinter滚动到 Tkinter 中的文本
【发布时间】:2014-06-05 18:22:17
【问题描述】:

大家好,我有一个文本框,可以搜索字符串并突出显示它们,效果很好。问题是测试框很长,用户可能需要滚动几分钟才能找到突出显示的字符串。我正在寻找一种方法来设置滚动条的位置,以便突出显示的字符串的第一次出现位于顶部。我希望这是有意义的,这是我的突出显示功能..

    def highlight(self, args):
    idx = '1.0'
    if (args == "clear"):
        self.dp_text.tag_remove('found', '1.0', END)
    if args=="":
        return
    while 1:
        # find next occurrence, exit loop if no more
        idx = self.dp_text.search(args, idx, nocase=1, stopindex=END)
        if not idx: break
        # index right after the end of the occurrence
        lastidx = '%s+%dc' % (idx, len(args))
        # tag the whole occurrence (start included, stop excluded)
        self.dp_text.tag_add('found', idx, lastidx)
        # prepare to search for next occurrence
        idx = lastidx
    self.dp_text.tag_config('found', foreground='red', background='yellow')

我认为这将是类似的东西

self.scrollbar.set(float(idx))

【问题讨论】:

    标签: python tkinter logic scrollbar


    【解决方案1】:

    不需要做滚动条运算:

    self.dp_text.see(idx)
    

    【讨论】:

      猜你喜欢
      • 2020-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-12
      • 2011-05-24
      • 2018-08-21
      相关资源
      最近更新 更多