Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

toplevel open/close event

15 views
Skip to first unread message

arlie

unread,
Mar 1, 2007, 6:48:01 PM3/1/07
to
Does a toplevel have an open/close event? How do you execute a proc
when such event is triggered?

Donal K. Fellows

unread,
Mar 1, 2007, 7:48:11 PM3/1/07
to
arlie wrote:
> Does a toplevel have an open/close event? How do you execute a proc
> when such event is triggered?

It depends on exactly what you mean and on what platform you are
running. However, at a guess you're after <Map> and <Unmap>, or
possibly <Configure> and <Destroy> (I don't think we deliver <Create>
events at the moment, and I'm fairly sure that Tk never gives you
<Expose> events). If you're on OSX, also try <Activate> and
<Deactivate>.

Be aware that binding to a toplevel means that you also get events
directed to child widgets of that toplevel; your bindings (probably)
need to check whether '%W eq [winfo toplevel %W]' is true...

Donal.

Jonathan Bromley

unread,
Mar 2, 2007, 4:40:46 AM3/2/07
to
On 1 Mar 2007 16:48:11 -0800, "Donal K. Fellows"
<donal.k...@man.ac.uk> wrote:

>arlie wrote:
>> Does a toplevel have an open/close event? How do you execute a proc
>> when such event is triggered?
>
>It depends on exactly what you mean

The OP may also wish to check out [wm protocol] as a way to
intercept attempts to close/destroy the toplevel.
--
Jonathan Bromley, Consultant

DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services

Doulos Ltd., 22 Market Place, Ringwood, BH24 1AW, UK
jonathan...@MYCOMPANY.com
http://www.MYCOMPANY.com

The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.

arlie

unread,
Mar 2, 2007, 5:08:30 AM3/2/07
to
On Mar 2, 12:48 am, "Donal K. Fellows" <donal.k.fell...@man.ac.uk>
wrote:


I'm new to Tcl/Tk. What I want is to execute a proc when a top level
opens, when it gets focus and as well when it closes. I'm developing
my program right now in MS Windows but this is also has to run on
Ubuntu and Suse linux.

Please give an example on how this is done since I have a very tight
development schedule. I need to get this up an running as soon as
possible. Thanks!


Donal K. Fellows

unread,
Mar 2, 2007, 6:15:23 AM3/2/07
to
arlie wrote:
> I'm new to Tcl/Tk. What I want is to execute a proc when a top level
> opens, when it gets focus and as well when it closes.

OK, that helps a lot.

The events that you're looking for are:
<Map> - delivered when a window becomes usable
<FocusIn> - delivered when a window gets the focus
<Unmap> - delivered when a window becomes iconified or withdrawn
<Destroy> - delivered when a window is killed

When binding to toplevels, be aware that they get events from all
widgets inside them as well, a feature that is used for things like
keyboard accelerators, etc. In this case, this means that your
bindings will need to use %W to check who the event was sent to and
act appropriately. With <FocusIn> events, you should also use %d to
filter out events that aren't relevant (there are lots of events about
in focus management, most of which you don't need).

To try this all out, try this little script:

# Done as a procedure so that the bindings are guaranteed
# to be applied before the window is first mapped
proc setup {} {
toplevel .t
pack [entry .t.e]
bind .t <Map> {puts "mapped %W"}
bind .t <FocusIn> {puts "focus %W %d"}
bind .t <Unmap> {puts "unmapped %W"}
bind .t <Destroy> {puts "destroyed %W"}
}
setup
# Now just play around with things to make some events!

On Unix, there are also <Visibility> events which are handy for this
sort of thing. Unfortunately, they're not supported on Windows; the
underlying system simply doesn't provide the information.

Hopefully that's enough for you to figure out how to achieve what your
real goal is.

Donal.

arlie

unread,
Mar 2, 2007, 6:58:38 AM3/2/07
to
On Mar 2, 11:15 am, "Donal K. Fellows" <donal.k.fell...@man.ac.uk>
wrote:

Thank you very much!

arlie

unread,
Mar 5, 2007, 2:38:47 PM3/5/07
to
On Mar 2, 11:15 am, "Donal K. Fellows" <donal.k.fell...@man.ac.uk>
wrote:


Me again. Where I can I find the referrence/manual for :

Bryan Oakley

unread,
Mar 5, 2007, 2:45:15 PM3/5/07
to
arlie wrote:
> Me again. Where I can I find the referrence/manual for :
>
> The events that you're looking for are:
> <Map> - delivered when a window becomes usable
> <FocusIn> - delivered when a window gets the focus
> <Unmap> - delivered when a window becomes iconified or withdrawn
> <Destroy> - delivered when a window is killed
>
>

The bind man page.

http://www.tcl.tk/man/tcl8.4/TkCmd/bind.htm


--
Bryan Oakley
http://www.tclscripting.com

arlie

unread,
Mar 5, 2007, 6:52:06 PM3/5/07
to

Thnaks

0 new messages