Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: tk bindings and readonly?

by converter (Priest)
on Dec 10, 2003 at 22:47 UTC ( #313908=note: print w/replies, xml ) Need Help??

in reply to tk bindings and readonly?

Without seeing your code it's difficult to guess what you're doing wrong, but in a nutshell, you should bind a callback to the parent MainWindow, for example:

use Tk; $mw = tkinit; $mw->Text->pack; $mw->bind('<Control-s>', sub { print "save something...\n" }); MainLoop;

The parent widget gets the keyboard input and responds to it instead of passing the event to the Text widget. If this doesn't fix the problem or doesn't address the right problem, post a snippet of code that shows what you're trying to do.

Replies are listed 'Best First'.
Re: Re: tk bindings and readonly?
by converter (Priest) on Dec 10, 2003 at 23:54 UTC

    I made a mistake here. When the Text widget has focus, the C-s character is still inserted. After re-reading the docs, it looks like the best approach for an instance binding would be something like:

    use Tk; $mw = tkinit; $t1 = $mw->Text->pack; $t1->bind('<Control-s>', sub { print "foo\n\n"; $_[0]->break }); # the order of bindtags is: # class name (Tk::Text), window name, ancestral toplevel, "all" # this modifies the tag list so that the instance binding, # which includes a call to break(), has higher priority # than the class binding $t1->bindtags([($t1->bindtags)[1,0,2,3]]); MainLoop;

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://313908]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2021-02-27 16:23 GMT
Find Nodes?
    Voting Booth?

    No recent polls found