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

  • Thread starter Thread starter berkeman
  • Start date Start date
Click For Summary
SUMMARY

The discussion focuses on creating a simple GUI using Tcl/Tk for a test program that indicates pass or fail results. The user is struggling with button placement and sizing, specifically the inconsistency between pixel units used in the configure statement and character/row units in button height and width. The user has experimented with various placement commands such as Place, Pack, and Grid but has not found an intuitive solution. The provided code demonstrates a basic layout with buttons for running tests and quitting the application.

PREREQUISITES
  • Familiarity with Tcl/Tk GUI programming
  • Understanding of widget placement methods: Place, Pack, Grid
  • Knowledge of button configuration options in Tcl/Tk
  • Basic programming skills in Tcl
NEXT STEPS
  • Explore advanced Tcl/Tk widget placement techniques
  • Learn about the differences between pixel and character units in Tcl/Tk
  • Research best practices for designing user interfaces in Tcl/Tk
  • Investigate the use of frames for better layout management in Tcl/Tk
USEFUL FOR

Developers creating graphical user interfaces with Tcl/Tk, particularly those designing test applications or needing to optimize button layouts and placements.

berkeman
Admin
Messages
69,508
Reaction score
25,060
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:
[code]
# 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:
Technology news on Phys.org
RF Ping Test Screenshot.jpg
 

Similar threads

Replies
9
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 4 ·
Replies
4
Views
5K