Bind Mouse button on tree widget - hwtk::treectrl

vipin_22401
vipin_22401 Altair Community Member
edited October 2020 in Community Q&A

Hi all,

 

Is it possible to bind mouse button operations on hwtk treectrl widget?

For example I have created a tree like below, when i click on any item, it should act as a button and execute some command.

 

image.png.0792975ac3fda25b9b479f3f75be8a2b.png

 

Answers

  • tinh
    tinh Altair Community Member
    edited April 2018

    Hi Vipin

    did you try setting a callback for option -selectcommand when creating the treectrl ?

    when you select some thing it will invoke -selectcommand

  • vipin_22401
    vipin_22401 Altair Community Member
    edited April 2018

    Hi @tinh

     

    I added -selectcommand as you said.

    Anything I select in the tree it is running that command, but how do I assign different script/command for each of the buttons?

     

     

  • tinh
    tinh Altair Community Member
    edited April 2018

    Hi Vipin

    example 

    set t [hwtk::treectrl $treewnd -selectcommand 'p_AtSelected %W']

    proc p_AtSelected t {

         set items [$t select]

         #you may select more than 1 item so pls handle it

          foreach item $items {

               set text [$t item text $item 0]

               switch -- $text {

                     button1 {

                           ...

                      }

                      button2 {

                           ... 

                       }

                       ... ...

                 }

            }

    }

  • vipin_22401
    vipin_22401 Altair Community Member
    edited April 2018

    Hey tinh,

     

    Thanks a lot for the help. It is working perfectly!!

    I Added -selectmode single, so multiple selection solved :)/emoticons/default_smile.png' srcset='/emoticons/smile@2x.png 2x' title=':)' width='20' />

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited October 2019

    can u share me this macros