Tcl/Tk Made Easy

Well, you've finished making your first Tcl/Tk application. Was it that hard? Probably not. But you say you want easier? Well, there are a few GUI builders out there for Tcl/Tk. An older one, XF, was written with the older versions of Tcl/Tk in mind. A newer one, SpecTcl, uses the latest versions of Tcl/Tk, but is still in early stages of development (read: Has some bugs)

To start SpecTcl, just type 'spectcl'. You will see a window pop up on the screen. It may take a few seconds to locate all the widgets, but be patient.

Now we will try to recreate the colorsel application we just did by hand using this GUI tool. Unlike the last method, we're going to set up the packing first (it takes care of it for you). So we want to set up the frames as we like.

  1. First, click in the upper right hand square of the frame grid. The frame bars should turn red. Go to the edit menu and select delete (Your delete key may also work, depending on how you have set up your environment). The internal frames should go away, and we should have one big empty frame. We need 5 vertical areas, so we will create them.

  2. Move your cursor over the top or bottom edge of the frame. That edge should turn red. Click your button to create a new area. Repeat until you have five horizontal areas (three for scales, one for the entry frame and one for the canvas).


  3. On the left side of the screen you will see a list of widgets. Go to the scale widget, and click and drag it to the top frame. A scale should appear in the top frame. Now we must edit the scale's attributes. You can do this by double clicking on the scale in the frame. Click Dismiss when you are done.

  4. Scroll through all the options available. There are a few we are interested in modifying. To modify a command click in the entry and modify the field. Pressing return will make the changes. There are also graphical ways of changing the common attributes of a widget. For the scale we want to set these fields
    command:       newColor
    item_name:     redscale
    label:         Red
    length:        7c
    orient:        h
    to:            255
    

  5. Now we want to create 2 other scales for Green and Red. You can either repeat the process again, or you can click on the red scale so its frame is highlighted red, go to the edit menu, and select copy. Then click the empty frame you want to copy the widget into so it is highlighted red, and go to the edit menu and select paste. You will still have to modify the widget, but not as much (only the item_name, and label).

  6. Next we will throw a canvas into the bottom frame. Just click and drag it there. Double click on it to edit it's options
    height:        1.5c
    item_name:     colorwin
    width:         7c
    

  7. Now we need to put a frame in for the entry boxes. Unfortunately this is one area where SpecTcl has some bugs. When you insert a frame you can't really resize it to make it smaller. Well you can, but it's not visible on the screen so we will just ignore it. Insert the frame by dragging the frame into the last remaining area. Double click on it to bring up it's options
    height:        1.5c
    item_name:     entryframe
    width:         7c
    

  8. Next create 4 vertical frame areas, much like we did with the horizontal ones of the top level frame.
  9. Then drag an entry widget into the left most frame. Edit the options for the entry and set these fields
    item_name:    redentry
    textvariable: redvar
    width:        7
    
  10. Now either create or copy similar entries for green and blue and modify their item_name, textvariable, and width. Be warned, if you copy, be sure to get the inner frame highlighted, or else it will copy the entry over the frame!

  11. Now get a button widget and drag it into the right most frame of the entry frame. Double click to set its options
    command:      setColor
    item_name:    setbutton
    text:         Set
    
  12. Once you are done with that, you've created the layout of your application. Finally we have to write the Tcl code for the callbacks. Select the Edit menu and click on edit code. A window will pop up for you to write the Tcl code for your callbacks. Because of the way Spec handles the geometry the the same code from before will not work. It's just a slight modification. The entry widgets are not children of the entryframe.
    
    proc newColor value {
            set color [format #%02x%02x%02x [.redscale get] [.greenscale get] [.bluescale get]]
            .colorwin config -background $color
    }
    
    proc setColor {} {
            .redscale set [.redentry get]
            .greenscale set [.greenentry get]
            .bluescale set [.blueentry get]
    }
    
    
  13. After that, you can go to the Command menu item and select Build and test and it will spawn your application for you. You can test it as before. Once you are satisfied, you can select the File menu, and save, then quit. This creates two files in your directory
    
    untitled.ui
    untitled.ui.tcl
    

    The *.ui file is for SpecTcl, the *.tcl file is your application. To use it Just create a file called 'testapp' with this in it
    
    source untitled.ui.tcl
    untitled_ui .
    
    
  14. Afterwards just issue
    blt_wish -f testapp
    

Augh...enough! This is making my head spin...I want to quit, but not before I see where I can get more information