Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

A little help with a simple Tcl/Tk window/buttons layout

  1. Jul 7, 2016 #1


    User Avatar

    Staff: Mentor

    I've used other Tcl/Tk widgets for manufacturing test programs a few years ago, but I'm making a simple test GUI now and am using a different approach. It's a simple test program that I want to have a simple GUI for. Basically it executes a test and displays whether the test passed or failed. Simple stuff.

    But I've been struggling a bit finding the simplest way to place the buttons with the sizes and placements that I want. I've tried out the Place, Pack, Grid, and other Tk widget placement commands, and have not found a scheme that works and is intuitive for me.

    My initial question is why does the configure statement seem to use units of pixels (maybe?), while the button -height and -width statements seem to use units of characters and rows?

    Is there a better and more consistent way of placing buttons in a Tcl/Tk window? The code below gives a fairly well-placed window with buttons on the Windows systems I've tested it on, but the disconnect between the . size and the button placements and sizes worries me.

    Thanks for any help, and thanks for any overall comments about the code or style. :smile:
    Code (TCL):

    # Basic work to start RF Ping Test

    # Configure window size
    . configure -width 375 -height 300

    # Create Quit and Run buttons
    set quitbutton [ button .quitbutton -text "Quit" -command "exit" ]

    set gobutton [ button .gobutton -text "Run RF Ping Test" \
        -height 3 \
        -command { $passbutton configure -bg green } ]

    # Create Pass and Fail buttons
    set passbutton [ button .passbutton -bg white -text "PASS" \
        -width 20 -height 10 \
        -command { $passbutton configure -bg white } ]

    set failbutton [ button .failbutton -bg white -text "FAIL" \
        -width 20 -height 10 \
        -command { $failbutton configure -bg white } ]

    # Place Pass/Fail buttons near the top
    place $passbutton -y 0 -x 0
    place $failbutton -y 0 -x 200

    # Place Go and Quit buttons near the bottom
    place $gobutton -y 175 -x 125
    place $quitbutton -y 250 -x 300

    EDIT -- BTW, the actual test code is not in the script yet -- right now it always shows a Pass. The user will click the Pass or Fail to clear the test result.
    Last edited: Jul 12, 2016
  2. jcsd
  3. Jul 7, 2016 #2


    User Avatar

    Staff: Mentor

Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted