Hi, On Sat, 08 Aug 2015 17:59:16 +0300 Alexander Uvizhev <uvi...@yandex.ru> wrote:
> > 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 (...) > > Is it what's supposed to be or some sort of bug? I guess something like this happens: * the text widget is created, but initially, before it is actually drawn onto screen, has virtually a size of 1*1 px * because of this the inserted 10-character text string is wrappped into 10 lines * this is when the first <Configure> event is triggered and so it in fact correctly reports 10 lines * subsequent calls to insert() do not trigger a <Configure> event * the next >cConfigure> event is triggered when the window is actually drawn after mainloop() is called, however in your example then the binding was already removed I modified your example a little to illustrate what I mean, without the unbind(); you can see then that after the window is visible the reported lines are as expected: ############################### import tkinter def check(event): print(event.widget.winfo_width(), event.widget.winfo_height()) print(event.widget.count('1.0', 'end', 'displaylines')) print() root = tkinter.Tk() master = tkinter.Frame(master=root) master.pack(fill='both', expand=1) text = tkinter.Text(master=master) text.bind('<Configure>', check) text.pack(fill='both', expand=1) text.insert('1.0', "1234567890") # first time insert text.insert('1.0', "1234567890") # second master.mainloop() ############################## Best regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. A star captain's most solemn oath is that he will give his life, even his entire crew, rather than violate the Prime Directive. -- Kirk, "The Omega Glory", stardate unknown _______________________________________________ Tkinter-discuss mailing list Tkinter-discuss@python.org https://mail.python.org/mailman/listinfo/tkinter-discuss