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

  • Thread starter Thread starter berkeman
  • Start date Start date
Click For Summary
The discussion centers on creating a simple GUI for a manufacturing test program using Tcl/Tk. The user is facing challenges with button placement and sizing, having experimented with various layout commands such as Place, Pack, and Grid without finding an intuitive solution. A key concern is the inconsistency in measurement units, where the configure statement appears to use pixels, while button dimensions are defined in characters and rows. The user seeks advice on achieving a more consistent and effective method for button placement within the Tcl/Tk window. Additionally, the code shared demonstrates the initial setup for the GUI, including the configuration of buttons for running tests and displaying results, though the actual test logic has not yet been implemented.
berkeman
Admin
Messages
69,299
Reaction score
24,521
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
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

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