Get the clipboard's text using Tkinter. This is the default on systems that are not Windows or OS X. It may interfere with other UI toolkits and should be replaced with an implementation that uses that toolkit.
()
| 44 | return text |
| 45 | |
| 46 | def tkinter_clipboard_get(): |
| 47 | """ Get the clipboard's text using Tkinter. |
| 48 | |
| 49 | This is the default on systems that are not Windows or OS X. It may |
| 50 | interfere with other UI toolkits and should be replaced with an |
| 51 | implementation that uses that toolkit. |
| 52 | """ |
| 53 | try: |
| 54 | from tkinter import Tk, TclError |
| 55 | except ImportError: |
| 56 | raise TryNext("Getting text from the clipboard on this platform requires tkinter.") |
| 57 | |
| 58 | root = Tk() |
| 59 | root.withdraw() |
| 60 | try: |
| 61 | text = root.clipboard_get() |
| 62 | except TclError: |
| 63 | raise ClipboardEmpty |
| 64 | finally: |
| 65 | root.destroy() |
| 66 | text = py3compat.cast_unicode(text, py3compat.DEFAULT_ENCODING) |
| 67 | return text |
| 68 | |
| 69 |