![]() |
Get selected text inside an Entry - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: Get selected text inside an Entry (/thread-29152.html) |
Get selected text inside an Entry - Jerdup - Aug-20-2020 Hi, sorry for inconvenience, this is my first post and I'm new with Python. I'm trying to understand how one can get the user-selected text inside a scrolledText entry (tkInter). I was fancying a button, and when you would click the button the program would get the part of the scrolledText content that is currently selected, if any (this is clearly visible on the screen). I thought there was a getSelectedText method or something like that attached to the entry, or at least that you could easily get the indexes of the beginning and the end of the selected text substring, but I searched the doc in vain. Thank you for any hint... ![]() from tkinter import scrolledtext # ... self.inp_encours = scrolledtext.ScrolledText(sframe3_1, width=86, height=35, font=("Arial", 10), bg=rdo_color, fg="black", wrap=WORD) # ... retour = self.inp_encours.get(1.0, "end") # that's OK to get the entire content, but now I would like to get just the selected part of it OMG, I finally just found it (on stackoverflow.com): myText = self.inp_encours.selection_get()How could I not have found it straight on, I dunno... Sorry... |