Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: Copy To Clipboard Highlighted Text From Text Widget Date: Tue, 22 Mar 2016 14:46:16 +1100 Lines: 21 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de Jpyr6fEYpgFKwAxfVXchzgxxabb0XWA1kFO/OeN8gJkw== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.059 X-Spam-Evidence: '*H*': 0.88; '*S*': 0.00; 'cc:addr:python-list': 0.09; '22,': 0.09; 'question.': 0.13; 'def': 0.13; '2016': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:Text': 0.16; 'wrote:': 0.16; 'try:': 0.18; 'thanks.': 0.18; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'posted': 0.21; 'code,': 0.23; 'header:In-Reply-To:1': 0.24; 'figure': 0.27; 'message- id:@mail.gmail.com': 0.27; 'actual': 0.28; 'looks': 0.29; 'code': 0.30; 'changed': 0.33; 'reference,': 0.33; 'tue,': 0.34; 'except': 0.34; 'received:google.com': 0.35; 'question,': 0.35; 'received:209.85': 0.36; '(and': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'thanks': 0.37; 'received:209': 0.38; 'thank': 0.38; 'easy': 0.60; 'future': 0.60; 'great': 0.63; 'you.': 0.64; 'mar': 0.65; 'python-list': 0.66; '2:36': 0.84; 'chrisa': 0.84; 'good!': 0.84; 'reading,': 0.84; 'to:none': 0.91; 'subject:From': 0.97 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc; bh=9yZSodw4rOVBIc+VJ6fym6+RmNFl9I8fpwcrIbVMVWU=; b=UFyw0/SKS3eXduRZbZz0WLOx+8GrBqF5UJ9ranel97yj+i8qGyxV5JDjgPLjJ0KLyw 6pFD6AP4ICWv5SpQ6e6LEiV07rWViho31QRUZZDfhqt6q0vqpxCUi6PP6k8eFI9+f9iO GUFJMeaAJuMs1RgVC71yqb2IgAAbdiPRIzAc/A6q54E4ETSBqKo0MKj6VfjVmHOumCuq 5CgRw1bFaCCfiD5vng/a1N1k4NER2KrbFLP8fI21KGUli67twLbhqz8nWcmvGWJI8KAR 5Lua0rIOBH/zHAvH30SlU57spu2huGKwnG6yVnAqIEfAlX5p57Z4RcNZtouyYUJkz/Ek 2Skg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:cc; bh=9yZSodw4rOVBIc+VJ6fym6+RmNFl9I8fpwcrIbVMVWU=; b=CmFOTyvmlf+NBSK8wS9C6Hp1VfQxbG23vI+1QJQazuHZwlfJHTDjzNkegmsgx3maTP +8OCXwyyKUqtOpn/mU646SxvrCnZyxM97Y4FXavvLtvyFQeJ+zF0alQw0KVm/jYQMUm7 sOw6zSGMQ/ftOLKspmzyd0YiCDKez6iV6995hIFR0kU+VL7Vuos7CXMqEETQ+RZgiaFw LEhyRD4F0TxKctdz14qsogVJ2M/PlNkMZhzuqN8s6hppGc+czdWGBwnB7dT7eqsFEbbW 0e7u4rIF50k+gErK08jKYorawRMCHa4F/p25SbRiiDuuTcUfZpSGtE+/d5qXC5zjg22F UJow== X-Gm-Message-State: AD7BkJKItDEdooBhyllUKvlalD5cs5IU1XnNUVB1sPCUZOaP8NpTyPOE/4v8f5VneZMiHU3bHoNgoddgbVUaUw== X-Received: by 10.112.147.101 with SMTP id tj5mr9792026lbb.119.1458618376907; Mon, 21 Mar 2016 20:46:16 -0700 (PDT) In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:105440 On Tue, Mar 22, 2016 at 2:36 PM, Wildman via Python-list 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