[Tkinter-discuss] Text widget tag_bind(), can't get it to work.

ron.longo longorh at npt.nuwc.navy.mil
Wed Apr 23 15:08:07 CEST 2008

I'm trying to catch a keypress event in a tagged region of text.  According
to the documentation this should work, however, my callback never gets
called.  Here's some test code:

from Tkinter import *

def typed( event=None ):
   print 'typed'

def moved( event=None ):
   print 'moved'

root = Tk()

text = Text( root )

text.insert( '1.0', '0123456789012345678901234567890' )
text.tag_add( 'try', '1.10', '1.19' )
text.tag_bind( 'try', '<Key>', typed )
text.tag_bind( 'try', '<Motion>', moved )

root.mainloop( )

So, my moved function gets called whenever the mouse enters and moves within
the tagged region.  However, if I have the insert cursor in the tagged
region and press any key, my typed function never gets called.  Am I doing
this incorrectly?  Am I misunderstanding how this is supposed to work?

View this message in context: http://www.nabble.com/Text-widget-tag_bind%28%29%2C-can%27t-get-it-to-work.-tp16834587p16834587.html
Sent from the Python - tkinter-discuss mailing list archive at Nabble.com.

More information about the Tkinter-discuss mailing list