Python Forum
Get selected text inside an Entry
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get selected text inside an Entry
#1
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... Huh

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...
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] compare entry with value inside file rwahdan 1 2,052 Jun-19-2021, 08:01 AM
Last Post: Yoriz
  [Tkinter] Get the last entry in my text widget Pedroski55 3 6,295 Jul-13-2020, 10:34 PM
Last Post: Pedroski55
  [Tkinter] Get text entry in frame1, echo it in frame2 Pedroski55 8 3,862 Jul-10-2020, 11:51 PM
Last Post: Pedroski55
  [Tkinter] finding lines from a text entry Sutsro 2 1,892 May-04-2020, 09:19 AM
Last Post: Sutsro
  Transfer Toplevel window entry to root window entry with TKinter HBH 0 4,427 Jan-23-2020, 09:00 PM
Last Post: HBH
  Update value selected in option menu when select an item from text box klllmmm 2 4,953 Jun-06-2019, 04:51 AM
Last Post: klllmmm
  [Tkinter] getting Entry text Stauricus 4 2,970 May-10-2019, 08:24 PM
Last Post: swanysto
  [Tkinter] how to get the entry information using Entry.get() ? SamyPyth 2 3,457 Mar-18-2019, 05:36 PM
Last Post: woooee
  [WxPython] bind label and entry text with return key metulburr 1 3,215 Aug-14-2018, 10:02 PM
Last Post: metulburr
  [Tkinter] Hide text in entry box when i click on it. MeeranRizvi 1 11,054 Jan-25-2017, 10:38 AM
Last Post: MeeranRizvi

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020