1

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

Nirvan
  • 15
  • 7
  • I can't really figure out your code from this fragment, but if you remove the `catch` you will most likely get an error message that gives you a hint as to why the `closeImage` variable is empty. – Peter Lewerin Jun 01 '15 at 15:48
  • @peter-lewerin : yes I have an error without catch (), I set catch to try – Nirvan Jun 01 '15 at 15:55
  • That error should probably be dealt with, not swept under the rug. – Peter Lewerin Jun 01 '15 at 15:59
  • OK, using : set closeImage [%W identify element %x %y] I have the message that I should used tab or element. How I can get the clic on the close icon (image), thank you – Nirvan Jun 02 '15 at 07:26
  • I can't, and I won't, walk you through this in a comment thread. You have an error message that tells you what's wrong (bad syntax). Fix that, and if you get another error, fix that too instead of silencing it. You should be able to work it out. If you get *really* stuck, look at the guidelines and post a question that is answerable. Good luck. – Peter Lewerin Jun 02 '15 at 09:32
  • I resolved it, I tried to use Styles as it's explaned here (http://paste.tclers.tk/895?v=raw) I detect if th clic is on the close image or not. Thank you Peter Lewerin – Nirvan Jun 02 '15 at 13:23

0 Answers0