This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author roger.serwy
Recipients Rich.Rauenzahn, Todd.Rovito, dzabel, loewis, roger.serwy, terry.reedy
Date 2013-03-31.03:44:56
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1364701496.83.0.565132347936.issue14146@psf.upfronthosting.co.za>
In-reply-to
Content
It's definitely a "bug" with Tk. Whenever the Text widget loses focus, the selection highlighting goes away. The following example code brings up a focused text box with selected text. Clicking the button switches focus to the button itself and then back to the text widget. During that focus change, the selection highlight goes away.

from tkinter import *
main = Tk()
text = Text(main, width=40, height=10, wrap="char")
text.pack()
text.insert(INSERT, "".join(map(str, range(100))))
text.tag_add(SEL, "1.0", "end")
text.focus_set()
def jump():
    text.after(500, btn.focus_set)
    text.after(1000, text.focus_set)
btn = Button(main, text="Click me", command=jump)
btn.pack()
main.mainloop()


One possible solution would be to use the "<FocusOut>" and "<FocusIn>" events to substitute the "sel" tag with a custom tag so that the highlight remains when losing focus, and then replace it with the "sel" tag when gaining focus.
History
Date User Action Args
2013-03-31 03:44:56roger.serwysetrecipients: + roger.serwy, loewis, terry.reedy, Todd.Rovito, Rich.Rauenzahn, dzabel
2013-03-31 03:44:56roger.serwysetmessageid: <1364701496.83.0.565132347936.issue14146@psf.upfronthosting.co.za>
2013-03-31 03:44:56roger.serwylinkissue14146 messages
2013-03-31 03:44:56roger.serwycreate