1

我正在寻找添加绑定以关闭我的选项卡(ttk::notebook)。我正在使用 OO tcl(面向对象)

我添加了一个图像(图标 X),没关系,但是当我点击它时,绑定不正确?

你能帮我用 tcl OO 做吗?所以这是我的代码:

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"
}] }

我正在使用一个例子

4

0 回答 0