tk question - how do i bind to multiple events?

Discussion in 'Ruby' started by Max Williams, Oct 18, 2007.

  1. Max Williams

    Max Williams Guest

    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?
    --
    Posted via http://www.ruby-forum.com/.
     
    Max Williams, Oct 18, 2007
    #1
    1. Advertising

  2. From: Max Williams <>
    Subject: tk question - how do i bind to multiple events?
    Date: Thu, 18 Oct 2007 21:15:10 +0900
    Message-ID: <>
    > 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.
    -------------------------------------------------------------------------
    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 }
    -------------------------------------------------------------------------
    --
    Hidetoshi NAGAI ()
     
    Hidetoshi NAGAI, Oct 18, 2007
    #2
    1. Advertising

  3. Max Williams

    Max Williams Guest

    Hidetoshi NAGAI wrote:

    > 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!
    --
    Posted via http://www.ruby-forum.com/.
     
    Max Williams, Oct 18, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mr2_93
    Replies:
    1
    Views:
    3,663
    mr2_93
    Oct 2, 2005
  2. Daves
    Replies:
    1
    Views:
    651
    S. Justin Gengo
    Jan 6, 2006
  3. Replies:
    0
    Views:
    614
  4. Chris

    Events Events Events Please Help

    Chris, Aug 30, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    418
    Chris
    Aug 30, 2005
  5. Josef Wolf

    How to bind canvas events to tags?

    Josef Wolf, Sep 10, 2009, in forum: Ruby
    Replies:
    6
    Views:
    171
    Josef Wolf
    Sep 17, 2009
Loading...

Share This Page