Missing `count` method in Tkinter's Text widget

前端 未结 1 831
陌清茗
陌清茗 2021-01-24 17:39

I\'m trying to get the number of displayed lines in a Tkinter Text widget and I\'m looking at this question: What's the most efficient way to get a Tkinter Text widget'

相关标签:
1条回答
  • 2021-01-24 18:35

    This appears to be a bug in Tkinter. You can use a monkeypatch to add the missing method:

    def count_monkeypatch(self, index1, index2, *args):
        args = [self._w, "count"] + ["-" + arg for arg in args] + [index1, index2]
    
        result = self.tk.call(*args)
        return result
    
    Tkinter.Text.count = count_monkeypatch
    
    0 讨论(0)
提交回复
热议问题