Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

add close button to Bwidget notebook

Status
Not open for further replies.

vsdpsingh

Programmer
Mar 8, 2011
32
0
0
IN
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.

CODE :

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
 
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
 
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
 
is there anyone to solve this issue. I need it urgently.
Thanks in advance
 
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:

Code:
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
 
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..
 
Glad it worked out for you!

The user manual of the BWidget Notebook, explains:

-image
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.
 
thanks to all..
changing the bwidget code by adjusting the "textOffsetX" variable done my job completely.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top