Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


add close button to Bwidget notebook

add close button to Bwidget notebook

add close button to Bwidget notebook

I am developing GUI, which have a Bwidget Notebook. In this BWidget Notebook i need close button by which user can able to close the tab.


set w [toplevel .window]
wm title $w "WINDOW"
wm state $w normal
set frame [frame $w.h ]
set notebook [NoteBook $frame.nb -background #EDE9E3]
set tab1 [$notebook insert end tab1 -text "TAB 1" -background #EDE9E3 -image "logo"]
set tab2 [$notebook insert end tab2 -text "TAB 2" -background #EDE9E3 -image "logo"]
pack $frame -expand true -fill both
pack $notebook -expand true -fill both

So how to add one close button ahead of "TAB 1" text.

Please help me out.
Thanks in advance

RE: add close button to Bwidget notebook

If you're asking about putting a button on the tab itself next to the "label", I think you can't.  You can put an image there but I don't know how you'd bind it to an action.  You can, however put a button on the page.  Will that do?

Bob Rashkin

RE: add close button to Bwidget notebook

yes adding image will work.. I figured out to add image to ttk:notebook but still struggling with bwidget notebook..
i can add button on page also but that would not look nice,.
Hence adding image would work on bwidget notebook, but dont know how..
Thanks in advance

RE: add close button to Bwidget notebook

is there anyone to solve this issue. I need it urgently.
Thanks in advance

RE: add close button to Bwidget notebook

It took me a while, but with the help of the IDE that tG² provides and the easy access to the BWidget package, I could explore this Notebook widget and its script. It seems that a BWidget notebook is made up of a canvas. Thus bindings to canvas objects is what we need to create in order to create a functional close button!

Please give it a try:


proc set_close_bindings {notebook page} {
  $notebook.c bind $page:img <ButtonPress-1> "+;
    $notebook.c move $page:img 2 2
    set pressed \[%W find closest %x %y]
  $notebook.c bind $page:img <ButtonRelease-1> "+;
    $notebook.c move $page:img -2 -2
    if {\$pressed==\[%W find closest %x %y]} {set pressed \"\"; $notebook delete $page}

set_close_bindings $notebook tab1

RE: add close button to Bwidget notebook

WOW! great thanks to you. :) It works like awesome
just one more help. is there any way to move image on right side of tab.
because tab will look like..
..."LOGO"TAB1.x... "LOGO"TAB2.x ... "LOGO"TAB3.x
and so on..
Hence on left side i have logo but cross image will be on right.
Is there any way to move the image to right side..? ot adding 2 images on both sides of "TAB1"
Thanks in advance..  

RE: add close button to Bwidget notebook

Glad it worked out for you!

The user manual of the BWidget Notebook, explains:

    Specifies an image to display for the page at the left of the label

If I understood your second question correctly, I believe you would like to add an additional image on the right side, which is the actual [x] button. Since this widget only provides one image per tab-header, and only on the left side, I think your quest is only possible by hacking into the Notebooks script. Unfortnately, my free time is limited, but I would like to direct you to the script to examine:
<tcl-install folder>/lib/bwidget1.8/notebook.tcl

Search for the tagname ":img", thats the image they have used for the left side. Similar approuch could be followed for the image to be put on the right side, I am guessing.

RE: add close button to Bwidget notebook

thanks to all..
changing the bwidget code by adjusting the "textOffsetX" variable done my job completely.  

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close