📄 470-473.html
字号:
<HTML>
<HEAD>
<TITLE>Linux Configuration and Installation:Programming in Linux</TITLE>
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<SCRIPT>
<!--
function displayWindow(url, width, height) {
var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>
-->
<!--ISBN=1558285660//-->
<!--TITLE=Linux Configuration and Installation//-->
<!--AUTHOR=Patrick Volkerding//-->
<!--AUTHOR=Kevin Reichard//-->
<!--AUTHOR=Eric Foster//-->
<!--PUBLISHER=IDG Books Worldwide, Inc.//-->
<!--IMPRINT=M & T Books//-->
<!--CHAPTER=10//-->
<!--PAGES=470-473//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="467-470.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="474-477.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<P>The Tcl script that makes all this happen appears here:
</P>
<!-- CODE //-->
<PRE>
#!/usr/bin/wish
#
# toolbar.tcl
# Tcl script that puts a toolbar to launch
# programs at the bottom of the screen.
#
# Executes a command as a UNIX process.
#
proc exec_cmd { command } {
# Execute as a UNIX process in the background.
# We use eval to handle the messy details of
# separating the command into its elements.
# (Try it without eval and you'll see why.)
#
eval exec $command &
}
#
# Tcl/Tk procedure to place the
# current time in a widget. With Tcl 7.5,
# you can also use the clock command.
#
set title_interval 40000
set time_command "/bin/date \"+%I:%M %p\" "
global title_interval time_command
proc update_time { butn } {
global title_interval time_command
# Get current time.
set timestr [ eval exec $time_command ]
$butn config -text $timestr
# Set up command to run again.
after $title_interval " update_time $butn"
}
#
# Global commands to execute when
# toolbar buttons get pushed.
#
set cmds(man) "/usr/bin/X11/xman -notopbox -bothshown"
set cmds(mail) "/usr/bin/X11/xterm -ls -e elm"
set cmds(term) "/usr/bin/X11/xterm -ls"
set cmds(file) "/usr/bin/X11/xfm"
set cmds(xv) "/usr/bin/X11/xv"
set cmds(xmah) "/usr/bin/X11/xmahjongg"
# Make cmds array global.
global cmds
#
# Main program.
#
# Set window manager values.
wm geometry . +0-0
wm overrideredirect . true
#
# Frame to hold everything.
#
set back lightgray
frame .frame -relief raised -bd 2 -bg $back
.frame config -cursor top_left_arrow
#
# Logo/Name widget.
#
set title [format "Linux: %s" [ exec hostname ] ]
button .frame.logo -text $title \
-command { exit } -bg $back \
-relief flat -padx 8
pack .frame.logo -side left -fill y
#
# Create other widgets
# that make up our toolbar.
#
button .frame.man -text "Manuals" \
-command { exec_cmd $cmds(man) } \
-relief flat -padx 8 -bg $back
button .frame.mail -text "Mail" \
-command { exec_cmd $cmds(mail) } \
-relief flat -padx 8 -bg $back
button .frame.term -text "Shell" \
-command { exec_cmd $cmds(term) } \
-relief flat -padx 8 -bg $back
button .frame.file -text "File Manager" \
-command { exec_cmd $cmds(file) } \
-relief flat -padx 8 -bg $back
button .frame.xv -text "Images" \
-command { exec_cmd $cmds(xv) } \
-relief flat -padx 8 -bg $back
button .frame.xmah -text "Mahjongg" \
-command { exec_cmd $cmds(xmah) } \
-relief flat -padx 8 -bg $back
# Pack all the buttons, in order.
pack .frame.man .frame.mail \
.frame.term .frame.file \
.frame.xv .frame.xmah \
-side left -fill y
# Set up timer label.
label .frame.time -bg $back
update_time .frame.time
pack .frame.time -side left -fill y
pack .frame
# toolbar.tcl
</PRE>
<!-- END CODE //-->
<P>You can easily add your own commands, with three easy steps:
</P>
<DL>
<DD><B>1.</B> At the <TT>set</TT> <I>cmds</I> area, add your new UNIX command.
<DD><B>2.</B> At the <I>button</I> area, copy one of the button commands to create your own. You need to change the button’s name to <I>frame.yourname</I> or something like that. Also, ensure that it uses your command from the <I>set cmds</I> area.
<DD><B>3.</B> At the <B>pack</B> command right after the button area, add the name of your new button.
</DL>
<P>You can use these two scripts as examples to get you started scripting Tcl applications. One of the handiest parts of Tcl is that it’s supported on Windows and Macintosh systems. There’s a number of books available on Tcl, including <I>Graphical Applications with Tcl and Tk</I>; see Appendix A for details.</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="467-470.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="474-477.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
</td>
</tr>
</table>
<!-- begin footer information -->
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -