Technical data

Tcl/Tk and ModelSim
6-52 ModelSim EE/SE Tutorial
Example 1 - Create a "hello world" button widget.
Before you begin the examples make sure you have completed "Preparing for the
Tcl/Tk examples" (p51).
In this example you will study a "hello world" button that prints a message when
pressed.
1 Source the Tcl file from the ModelSim prompt:
source hello.tcl
then run the procedure defined within hello.tcl:
hello_example
The file hello.tcl was read into the VSIM Tcl interpreter. The instructions in
hello_example procedure were then executed by VSIM, and "Hello World" was
printed to the Main transcript. Selecting the button will print the message again.
You’ve just created your first top-level widget!
2 Invoke the hello_example procedure again and notice how the new button replaces the
original button. The procedure destroyed the first button and created the new one. Get
a closer look at the source Tcl file with the notepad:
notepad hello.tcl
Close the hello_example window when you’re done.
Example 2 - Add a procedure that gets called by a button push.
Before you begin this example make sure you have completed "Preparing for the
Tcl/Tk examples" (p51).
In this example you will study a larger Tcl example, and add a procedure that gets
called by a button push.
This example will display all of the gif images in the images directory. Each
button has a binding attached to it for "enter" events, and a binding for a mouse
button press. When the mouse enters the button graphic, the image file name is
printed to the Main window. When the mouse button is pushed its "widget" name
will be printed to the Main window.
1 Build an image viewer by invoking this command, and calling this procedure:
source images.tcl
image_example