Tabs in Preferences -> Options window

  • Nobody/Anonymous

    Hi. Can someone tell me how I can make my own tab windows, like those in your preferences->Options menu?

    • Nobody/Anonymous

      I can give two suggestions:

      1. Use one of the many opensource notebook widgets available for Tcl/Tk.

      2. Go through the source of SpecTcl to see how it is done here (this is the beauty of opensource). I wish I could help you more, but I haven't yet meddled with this part of the code.

      Whichever one you choose, it would be nice to hear how it worked.

      (who again didn't feel like logging in)

    • Nobody/Anonymous

      After attempting to install and use Tix, BLT, PMW and some other extensions, I decided that instead of spending any more time messing around with these libraries that I would "roll my own" notebook system, upon advice from Brent Welch, the author of Practical Programming in Tcl and Tk. I ended up making a frame of buttons above another frame, and the commands of each button pack the appropriate frame into the space below. The pivotal point, however, is using "place" to position a thin gray frame over the borders between the buttons and frames so that it looks as if the buttons are "attached" to the appropriate frames.

      ben lawson
      thomson multimedia

      • Nobody/Anonymous

        Interesting. Now I know how that part of SpecTcl was made. I think you chose the best solution - I also prefer to keep the number of extensions to a minimum.

    • Nobody/Anonymous

      How can I use spectcl (unix) to build a tab window like the Tabs in Preferences.
      Thank you

      • Nobody/Anonymous

        I've posted some code below. You can hack it to remove the [incr tcl] usage if you like. The two files "Fonts.ui.tcl" and "Colours.ui.tcl" are files you create yourself with SpecTcl.


        package require Itcl

        itcl::class notebook {
           variable root
           variable base
           variable tabs [list]
           variable offset
           constructor {ROOT args} {
              set root $ROOT
              if {"$root"=="."} {
                 set base ""
              } else {
                 set base $root
              frame $base.f -relief raised -bd 2
              place $base.f -relx 0.05 -rely 0.05 -relwidth 0.9 -relheight 0.85
              set xoffset 0
              foreach item $args {
                 ${item}_ui [frame $base.f$item]
                 label $base.l$item -text $item -relief raised -width 9
                 place $base.l$item -relx 0.05 -rely 0.9 -y -2 -x $xoffset
                 lower $base.l$item
                 bind $base.l$item <Button-1> [list $this sel $item]
                 update idletasks
                 lappend tabs $item
                 set offset($item) [expr $xoffset +2]
                 incr xoffset [expr [winfo width $base.l$item] +2]
              frame $base.ff0 -width [expr [winfo width $base.l[lindex $tabs 0]]-4] -height 3
              frame $base.ff1 -width 1 -height 2 -bg white
              sel [lindex $tabs 0]
           destructor {
              foreach w [winfo children $root] {
                 destroy $w
           method sel {TabID} {
              place $base.ff0 -relx 0.05 -rely 0.9 -y -2 -x $offset($TabID)
              place $base.ff1 -relx 0.05 -rely 0.9 -y -1 -x [expr $offset($TabID)-1]
              foreach item $tabs {
                 grid forget $base.f$item
                 $base.l$item config -bg #c8c8c8
              $base.l$TabID config -bg [$base.f cget -bg]
              grid $base.f$TabID -in $base.f -row 0 -column 0 -sticky news -padx 4 -pady 4
              grid rowconfigure $base.f 0 -weight 1
              grid columnconfigure $base.f 0 -weight 1
              update idletasks
              focus [tk_focusNext $base.f$TabID]

        # Example of usage
        source Fonts.ui.tcl
        source Colours.ui.tcl

        notebook nPreferences . Fonts Colours
        wm geometry . "500x300"


Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks