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

  • Thread starter berkeman
  • Start date
In summary, 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
  • #1
berkeman
Mentor
67,041
19,864
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
  • #2
RF Ping Test Screenshot.jpg
 

1. What is Tcl/Tk and how is it used for creating windows and buttons?

Tcl (Tool Command Language) is a scripting language used for creating applications and automating tasks. Tk (Toolkit) is a graphical user interface (GUI) toolkit that works with Tcl to create windows and buttons. Together, they allow for the creation of simple and user-friendly GUI elements.

2. How do I start designing a window layout with Tcl/Tk?

The first step is to create a main window using the "toplevel" command. This will serve as the parent window for all other widgets. Then, use the "pack" or "grid" command to add buttons and other widgets to the main window and arrange them in the desired layout.

3. How do I create buttons in Tcl/Tk?

To create a button, use the "button" command and specify its parent window, label, and any other options such as size and color. For example, "button .button1 -text "Click Me" -width 10 -height 2 -bg blue". This will create a button labeled "Click Me" with a blue background.

4. Can I customize the appearance of buttons in Tcl/Tk?

Yes, buttons in Tcl/Tk can be customized using various options such as size, color, font, and border. Additionally, the "configure" command can be used to change the appearance of a button after it has been created. For example, "configure .button1 -state disabled" will disable the button.

5. How do I handle button clicks in Tcl/Tk?

To handle button clicks, use the "bind" command and specify the event to be handled (such as for a left click) and the command to be executed when the event occurs. For example, "bind .button1 {puts "Button clicked!"}". This will print "Button clicked!" to the terminal when the button is clicked.

Similar threads

  • Programming and Computer Science
Replies
9
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
Back
Top