-->

Previous | Table of Contents | Next

Page 526

Listing 25.1. continued


proc setColor {value} {

global color;

foreach i {red green blue} {

set $i [format %02x [.scale_$i get]];

}

set color "#$red$green$blue";

.preview_label configure -bg $color;

.message_label configure -text "$color";

}



proc make_preview {} {

global color;



frame .preview_frame;

label .preview_label -bg $color \

-height 5 -width 5;

pack .preview_label -in .preview_frame \

-padx 2 -pady 2 -fill both -anchor c \

-expand 1;

pack .preview_frame -in .control_frame \

-side top -fill both -expand 1 \

-padx 2 -pady 2;

}



proc make_buttons {} {

frame .button_frame;

button .apply -text "apply" -command setRootColor;

button .quit -text "quit" -command exit;

pack .apply .quit -in .button_frame -fill both \

-expand 1 -padx 2 -pady 2 -side left;

pack .button_frame -in .main_frame -fill both;

}



proc setRootColor {} {

global color;



catch {

exec xsetroot -solid $color;

} msg;



if {$msg != {}} {

set msg "An error occurred";

} else {

set msg "$color";

}



.message_label configure -text $msg;

}



make_message_label;

make_scales;

make_preview;

make_buttons;

Page 527

Summary

This chapter is an introduction to programming in tcl/tk. The examples demonstrate the power of tcl/tk, which lies in the ability to make user interfaces within a short amount of time and with little code. Although this chapter covers many of the features of tcl/tk, there are many more that are not discussed. I hope that with this chapter as a stepping stone, you will enjoy many years developing tcl/tk applications.

Page 528

Previous | Table of Contents | Next