Eric Seifert
Eric Seifert

Reputation: 2032

Selected text in ruby Tk Text widget?

I can't seem to find how to get the currently selected text from a Text widget in ruby. In perl there was a ->getSelected function, which does not seem to exist in the ruby implementation. Also, the selected text is supposed to be marked with a tag "sel", but whenever I try to use it with get("sel"), it says invalid text index. There must be a way to get the selected text though...

Also, another question, by default, the text widget in perl has a pop menu with all sorts of functionality like search, copy/paste. Was this just a perl specific add on?

Upvotes: 0

Views: 560

Answers (2)

Bryan Oakley
Bryan Oakley

Reputation: 386220

Yes, the popup menu in perl is a perl-specific add-on.

As for getting the selected text, you are correct that the selected text has the "sel" tag, and you use that to get the selected text. To retrieve the selected text you should use the index sel.first and sel.last, for example:

get("sel.first", "sel.last")

A really good resource on Tk that covers usage in Tcl, Python, Ruby and Perl see tkdocs.com. The text widget is documented on that site in the tutorial on text.

Upvotes: 1

Eric Seifert
Eric Seifert

Reputation: 2032

Of course I finally figured this out right after posting. The index is "sel.first" and "sel.last". so I used get("sel.first", "sel.last")

Upvotes: 1

Related Questions