tk question - how do i bind to multiple events?

M

Max Williams

I have a text field, and i want to get the value out of it when the user
presses Return or tabs to another field. Currently i'm doing it like
this:

name_field = TkEntry.new(root)
var = TkVariable.new("f")
name_field.textvariable(name_var)
name_field.pack()

name_field.bind("Key-Return") { name_field_value = name_var.value }
name_field.bind("FocusOut") { name_field_value = name_var.value }

It seems like there should be a way to combine these, like

name_field.bind("Key-Return" || "FocusOut") #doesn't work
name_field.bind("Key-Return", "FocusOut") #doesn't work either

But these doesn't work. Can anyone tell me how to do this please?
 
H

Hidetoshi NAGAI

From: Max Williams <[email protected]>
Subject: tk question - how do i bind to multiple events?
Date: Thu, 18 Oct 2007 21:15:10 +0900
Message-ID: said:
name_field.bind("Key-Return") { name_field_value = name_var.value }
name_field.bind("FocusOut") { name_field_value = name_var.value }

It seems like there should be a way to combine these, like

name_field.bind("Key-Return" || "FocusOut") #doesn't work
name_field.bind("Key-Return", "FocusOut") #doesn't work either

But these doesn't work. Can anyone tell me how to do this please?

Please use TkVirtualEvent object.
 
M

Max Williams

Hidetoshi said:
Please use TkVirtualEvent object.
-------------------------------------------------------------------------
virt_ev = TkVirtualEvent.new("Key-Return", "FocusOut")
# or use TkVirtualEvent#add(seq, ...) / TkVirtualEvent#delete(seq, ...)

name_field.bind(virt_ev) { name_field_value = name_var.value }

Great, thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top