Showing posts with label python. Show all posts
Showing posts with label python. Show all posts

Sunday, February 17, 2008

Getting the Currently Selected Text in Tkinter

I tracked down the technique for getting the current text selection in Tkinter, as opposed to getting the current contents of the clipboard, and put them both in a nice neat function:
def _getCurrentText(widget, clipboard=False):
'''
Given a Tkinter widget, return the currently selected text (clipboard
is False) or the current contents of the system clipboard (clipboard
is True) or None if no text is currently available.
'''

try:
if clipboard:
return widget.selection_get(selection='CLIPBOARD')
else:
return widget.selection_get()
except TclError:
pass
The mechanics of that selection_get() method reach through Tk all the way to to the ICCCM standard and the X protocol!

Saturday, February 16, 2008

Pygoo site up.

Sarah set up the Pygoo.com website with a very nice CSS styling. It gives a little history of the code and has links to the Google Code project and some of the source sites.

Oh BTW, pygoo is a simple parser that creates Tkinter widgets from a Little Language textual specification.