![]() |
Tcl/Tk Tutorial: My First Splash ScreenLets say you would like to build a splash screen like the one below, which lists important phone numbers and email addresses at your site. You can do this using two types of Tk widgets: labels and buttons. We will do this first using the application wish, then we will write a script which will perform the same functions, and finally we will incorporate our script into our ANSYS environment.
Instead of compiling your code, Tcl/Tk uses wish as a Tcl/Tk interpreter that takes in Tcl/Tk scripts and creates the GUI widgets. We will demonstrate this by typing commands directly into the wish console. If you are using Windows, you can start the wish application by choosing Programs | Tcl | Wish from the Start Menu. If you are using UNIX, and if the Tcl/bin directory is in your environment path, simply type wish at the command prompt. You will see two windows. One is an input window for entering commands,
the other is a root graphics window that will contain any widgets that
we create. In the input window, issue the following command: This basically says, In the window, create the title, use the root
window as the destination and use the string ANSYS Support.
Notice the title of your root graphics window now displays ANSYS
Support instead of wish83. In this case, the .
in the previous command is the name of our root graphics window. All subsets
of this window will be preceded by a .. Next, well display
some useful phone numbers. Issue the following command: This creates the label called name1 in our root window with
the text given above in the double-quoted string. Nothing will appear
in our graphics window until we tell the interpreter how we would like
to display it. Weve just told the graphics manager that the label .name1
will be placed from the top of the main window. In addition, weve
specified that we want 10 pixels of space to separate this label and the
rest of the window. Also, in this particular case, the -side top
was actually redundant because by default all widgets are packed from
the top. We can create as many labels as we want and pack them as well.
For example, type in the following to add the other two labels and then
pack them in the window: Next, well want to create a button so that the user can dismiss
this dialog after they read the information. Weve now created and placed a button with the label OK
at the bottom of the window. Dont press this button yet! Upon pressing
this button, the application will issue the destroy
. command to remove the root graphics window and any children (i.e.,
our labels and button). When you are ready, press the OK
button to exit out of the wish environment. Next, well create a
script which will issue all of these commands automatically. Simply copy
the contents below into a file called splash.tcl. The first three lines will tell your operating system to invoke the wish interpreter, and all of the following lines will be issued as commands to the wish program. On a Windows machine, assuming Tcl/Tk has been installed properly, this is probably not necessary since all files with a .tcl extension are assumed to be Tcl/Tk scripts. Unix users will also have to add execute privileges to this file. Run the script either by double-clicking (for Windows users), or by typing the command splash.tcl. You should see a splash screen identical to the one we created earlier. Notice that weve added a few changes from our previous wish execution. Rather than use the main graphics window as the container for all of our widgets, we have withdrawn the main window so that the window manager will sort of forget about it, and created a new top-level window called .splash. A variable t has been set to .splash so that for each instance of $t.window, the window will be a child of .splash. The destroy .splash command is issued in the beginning as a safeguard, in case a window named .splash already exists (i.e., in the instance that the user runs the script twice without exiting). Now finally, lets incorporate this into ANSYS. Copy the file splash.tcl
into whatever directory is your ANSYS working directory and start up an
ANSYS interactive session. In the input window type: You should now see your splash screen. To add your splash screen to your
toolbar type the following: Now each time you press the SUPPORT button on your toolbar, your splash screen will show up. If you want this splash screen available to you every time you start ANSYS, simply locate the file start.ans in your ANSYS56/DOCU directory, copy it to your working directory and add the above command to the end of the file. Lastly, lets say you replaced Jane Doe and others with
actual people and useful phone numbers, and you would like to make this
available to all users. Copy the splash.tcl file to the ANSYS56/DOCU
directory. Edit the start56.ans file in the ANSYS56/DOCU directory
(making sure to back it up first) and add the following line: In this case you will probably replace C:/ ANSYS56 DOCU with the directory location of wherever ANSYS is located on your machine. Congratulations on successfully creating your first Tcl/Tk GUI for ANSYS! |
© Copyright 1994-2012 Phoenix Analysis & Design Technologies, Inc.
All rights reserved. :: 480.813.4884 |
Home | Contact Us | Site Map | Search | www.padtmedical.com
| ANSYS |
| Flownex Simulation Environment |
| 3D Printing/Production |
| Fuel Cell Accessories |
| CADfix |
| CUBE HVPC Computers |
| Cross Sectional Scanners |
| Laser Scanners |
| Geomagic Inspection Software |
| Stereolithography (SLA) |
| Selective Laser Sintering (SLS) |
| PolyJet Technology |
| Fused Deposition Modeling |
| Injection Molding |
| Rubber Molding |
| Model Shop |
| Vacuum Forming |
| Cross Sectional Scanners |
| Laser Scanning |
| PADT Medical |
| Power Systems |
| - Air & Fluid Handling |
| - Custom Blowers |
| - Custom Turbines |
| - Turnkey Systems |
| Vacuum Systems |
| - Design & Dev. |
| - Simulation |
| - Rapid Prototyping |
| - Dev. Solutions |