[Tkinter-discuss] Text widget incorrect 'displaylines' count

Alexander Uvizhev uvizhe at yandex.ru
Sat Aug 8 16:59:16 CEST 2015


Hi,
Recently I came across some strangeness in tkinter Text widget. I bind <Configure> event to it and the first time I insert text into widget the callback is called and reports wrong 'displaylines' count.
Here is the code:
===
$ cat test_text.py
import tkinter


def check(event):
    lines = event.widget.count('1.0', 'end', 'displaylines')
    print(lines)

root = tkinter.Tk()
master = tkinter.Frame(master=root)
master.grid()
text = tkinter.Text(master=master, height=1)
text.bind('<Configure>', check)
text.grid()
text.insert('1.0', "1234567890")  # first time insert
text.insert('1.0', "1234567890")  # second
text.unbind('<Configure>')
master.mainloop()
===
Output:
$ python3 test_text.py 
(10,)

Is it what's supposed to be or some sort of bug?

-- 
Alexander Uvizhev
uvizhe at yandex.ru


More information about the Tkinter-discuss mailing list