Is there any way to not select blank text in tkinter.
Here's the code:
from tkinter import *
root = Tk()
text = Text(root , width = 65 , height = 20 , font = "consolas 14")
text.pack()
text.insert('1.0' , "This is the first line.\n\nThis is the third line.\n\nThis is the fifth line.")
mainloop()
Here when I select a few lines, the blank text at the end of each line also gets selected.
What I want that the blank text should not get selected.
Is there any way to achieve this in tkinter?
It would be great if anyone could help me out.
It's not really an "area" being selected: the Text object contains (and selects) characters, not areas. It's important to distinguish the characters being selected, and their representation on the screen.
The last character in every line is a newline '\n'
(that's actually what
defines a line). When you move the mouse beyond the dot '.'
(to the right),
you're including the newline in your selection.
Now, the Text widget normally inverts foreground and background colors to indicate that a character is selected, but the newline is not explictly drawn as a character, it's actually invisible (apart from the fact that the text jumps to the following line). These blank areas that bother you are just the Text widget's way of telling you that you've selected the newline character, and I don't think you can change this display behaviour.