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 | |
Share this Question
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----- | |
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/ | |
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? | |
P: n/a
|
No I haven't, but I will give it a try.
Thanks for your reply! | |
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. | |
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? | |
P: n/a
|
Sorry, kinda wrote over your intentions... | |
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. | | This discussion thread is closed Replies have been disabled for this discussion. | | Question stats - viewed: 2305
- replies: 9
- date asked: Oct 25 '05
|