What's the most efficient way to get a Tkinter Text widget's total display lines after the insert?

前端 未结 2 1017
野趣味
野趣味 2021-01-22 04:57

Is there a more efficient way to get the total number of display lines (not just visible ones) that are left in a tkinter Text widget after the text in

2条回答
  •  北恋
    北恋 (楼主)
    2021-01-22 05:13

    If you only care about the time to scroll through the document, and if the data doesn't change as you're scrolling (ie: new lines aren't being added) you can simply calculate how many pixels the document takes up (you only have to do this once), and where you currently are in the document. That will tell you how many pixels are left. From that you should be able to calculate an approximation of how much time it will take.

    You can get the total number of pixels used in the text widget with myTextWidget.count("1.0", "end", "ypixels". You can then get the y coordinate of the current line with myTextWidget.dlineinfo("insert"). From those two numbers you can compute a percentage of how far the insertion point is from the end of the widget.

提交回复
热议问题