notebook ttk close tab

272 views Asked by At

I am looking to add a bind to close my tab (ttk::notebook). I am working with OO tcl (oriented object)

I added an image (icon X) and it's OK but when I click on it, the bind is not coorect ?

Can you help me to do it with tcl OO ? so this is my code :

oo::define CLASS method setTAB {command} {
my variable m_noteApp

set name [frame "toto"]
$m_noteApp add $name -text "TAB1" -image "close" -compound right
$m_noteApp select $m_noteApp.$command
my set_close_bindings $m_noteApp $m_noteApp.$command }


oo::define CLASS method set_close_bindings {notebook page} {

puts "tcl -- set_close_bindings $notebook, $page"

bind $notebook <ButtonPress-1> [callscript {
    puts "  ButtonRelease %W %x %y"
    # Widget parentW are OK

    set closeImage ""
    catch {set closeImage [%W identify component %x %y]}
    puts "  -- closeImage : $closeImage" 
    # test is always empty, I dont why ! I expect that it will returns the image close. 

    set pressed [%W identify element %x %y]
    puts "  -- %x %y, $pressed" 
    # pressed = "label" why it's not my close icon, I clic on it ?


    set varname [%W.$pressed cget -text]
    puts "  -- $varname" 
    # error : Invalid command  [%W.$pressed cget -text]     

}]   
 bind $notebook <ButtonRelease-1> [callscript {
    puts "  ButtonRelease %W %x %y"
}] }

I am using an exemple to

0

There are 0 answers