Copy To Clipboard Highlighted Text From Text Widget
Chris Angelico
rosuav at gmail.com
Mon Mar 21 23:46:16 EDT 2016
On Tue, Mar 22, 2016 at 2:36 PM, Wildman via Python-list
<python-list at python.org> wrote:
> Thanks. I changed the code as you (and MRAB) suggested.
>
> def copy_clipboard(self):
> try:
> text2copy = self.text.get(tk.SEL_FIRST, tk.SEL_LAST)
> except tk.TclError:
> text2copy = self.text.get()
> root.clipboard_clear()
> root.clipboard_append(text2copy)
>
> Works perfectly. Thanks again.
Looks good!
For future reference, and for others reading, this was a great
question. You posted actual code, with a specific question, and it was
easy to figure out what's going on. Thank you.
ChrisA
More information about the Python-list
mailing list