By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,985 Members | 1,575 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,985 IT Pros & Developers. It's quick & easy.

textwidget.tag_bind("name", "<Any-KeyPress>", self.donothing) not working

P: n/a
Hi all,

For some reason this bind is calling the donothing function, like it
should, but is then allowing the text to be inserted into the Text
widget.

Here is the code:

self.framebody.tag_config("name", underline=1)
self.framebody.tag_bind("name", "<Any-KeyPress>", self.donothing)

line = '\t%s' % ('sometext')
self.framebody.insert(END, line, "name")

def donothing(self):
return 'break'

This donothing function should keep the tcl bind from inserting the
text...at least so I thought.

This bind does work on the text widget as a whole, but on a individual
tag, it does not.

Can anyone help me out with this?

Thanks in advance,
Shannon

Oct 25 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
I'm not sure why Tk behaves this way, but you can observe the same behavior
with a "wish" script. It would seem that "break" skips any other scripts
associated with item tags, but still proceeds to bindings at the widget level.
Using a binding with "break" on the canvas itself may help you get the behavior
you want.

################################################## ######################
canvas .c -width 70 -height 70
set it [.c create text 20 20 -tags x -text example -anchor nw]
..c bind x <KeyPress> { puts "item binding"; break; }
bind .c <KeyPress> { puts "widget binding"; break }
bind . <KeyPress> { puts "toplevel binding"; break }

pack .c
focus .c
..c focus $it
################################################## ######################

Jeff

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFDXpdyJd01MZaTXX0RArf7AJkBHDwABPgHjOtspieasT iC+yxSUACfQJIk
EGk98dqUPvBKtycoRYpPmH4=
=fa5/
-----END PGP SIGNATURE-----

Oct 25 '05 #2

P: n/a
shannonl wrote:
Hi all,

For some reason this bind is calling the donothing function, like it
should, but is then allowing the text to be inserted into the Text
widget.

Here is the code:

self.framebody.tag_config("name", underline=1)
self.framebody.tag_bind("name", "<Any-KeyPress>", self.donothing)

line = '\t%s' % ('sometext')
self.framebody.insert(END, line, "name")

def donothing(self):
return 'break'

This donothing function should keep the tcl bind from inserting the
text...at least so I thought.

This bind does work on the text widget as a whole, but on a individual
tag, it does not.

Can anyone help me out with this?

Thanks in advance,
Shannon

Have you tried capturing the KeyRelease events as well?

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/

Oct 25 '05 #3

P: n/a
shannonl wrote:
Hi all,

For some reason this bind is calling the donothing function, like it
should, but is then allowing the text to be inserted into the Text
widget. [...] This bind does work on the text widget as a whole, but on a individual
tag, it does not.


You're trying to prevent a user from editing the text -within- a single
tag. Does Tk even support this?

Is your bind-applied-to-tag even firing, when the user presses a key
within a tag?
Oct 26 '05 #4

P: n/a
No I haven't, but I will give it a try.

Thanks for your reply!

Oct 26 '05 #5

P: n/a
I don't know if Tk supports this or not. I guess it just made since to
me that it should. If you can bind events to a tag then why not a tag
inside a text widget. The actual bind itself works. donothing() is
called, the problem is that after donothing() is called and I return
"break", Tk continues to insert the text entered. I am just try to
lock down one particular part of a text line while leaving the rest of
the line, which has a different tag, alone.

Oct 26 '05 #6

P: n/a
but you don't want to use the state=DISABLED option because it gray's
out the field showing people that it is not available for editing,
right?

Oct 26 '05 #7

P: n/a
Sorry, kinda wrote over your intentions...

Oct 26 '05 #8

P: n/a
To make amends, I tried my own search and came up with this (that you
might already have...):
http://groups.google.com/group/comp....&start=1&num=3

Maybe you'll understand it better than me :-)

Oct 26 '05 #9

P: n/a
Thanks for your help and the link. From the link it sounds like no one
is sure how this is supposed to act. I will dig around in the tcl
forum and see what I can find.

Oct 31 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.