{Possible_Spam} tkinter text editor

John McMonagle jmcmonagle at velseis.com.au
Fri Mar 9 01:29:49 CET 2007

Gigs_ wrote:
> I'm writing text editor.
> How to enable/disable (cut, copy etc.) when text is selected/not selected

Bind the Button1-ButtonRelease event to a function which checks the 
length of the SEL tag of the text widget.  If it is zero length, disable 
the appropriate menu entries, if it is non-zero, enable the appropriate 
menu entries.

Simple example:

from Tkinter import *
root = Tk()

textWidget = Text(root)

def onButton1Release(event):
     if len(textWidget.tag_ranges(SEL)) == 0:
         print 'No text selected.  Disable appropriate menu entries'
         print 'Some text selected.  Enable appropriate menu entries'

textWidget.bind('<Button1-ButtonRelease>', onButton1Release)


More information about the Python-list mailing list