ICONS - Examples
Home Man Page viewIcons Libraries Examples Download License Contact

A Simple Example

It is best to use a simple example to demonstrate the usage of the ICONS package:

# Request the ICONS package and import the "icons" command.
package require icons 2.0
namespace import icons::icons

# Use the "icons" command to create two icons "actreload16" and "navhome16".
# As no icon library file has been specified it is assumed that the required
# file is called "tkIcons" in the directory given by the "info library" command.
icons create {actreload16 navhome16}

# Create two buttons with the previously created icons.
# NOTE: When the icon images are created the names are prefixed with "::icon::".
button .b1 -relief flat -image ::icon::actreload16
button .b2 -relief flat -image ::icon::navhome16

# Pack the buttons into the window. The "-padx" options are simply to create a 
# gap between the buttons.
pack .b1 -padx 2 -side left
pack .b2 -padx 2 -side left
The above script will create the following:

Using Create

Where the "file" identifies an ICONS library file:

icons create {actreload16 navhome16}
Create images for the two specified icons (As in above "Simple Example") using the default library.

icons create -file tkIcons.ikons {actreload16 navhome16}
Create images for the two specified icons using the "tkIcons.ikons" library in the directory given by the "info library" command.

icons create -file /home/mydir/myIcons {myicon1 myicon2}
Create images for the two specified icons using the "/home/mydir/myIcons" library.

icons create -group edit
Create images for all icons belonging to the "edit" group using the default library.

icons create -group {edit file}
Create images for all icons belonging to the "edit" and "file" groups using the default library.

icons create -group {edit file} {actreload16 navhome16}
Create images for all icons belonging to the "edit" and "file" groups and the two specified icons using the default library.

icons create -file tkIcons.ikons -group {edit file}
Create images for all icons belonging to the "edit" and "file" groups using the "tkIcons.ikons" library in the directory given by the "info library" command.

icons create -group *
Create images for all icons in the default library.


Where the "file" identifies a folder containing GIF/PNG image files:

icons create {myicon1 myicon2}
Create images for the two specified icons using image files in the default folder.

icons create -file "C:/myapp/Icons" {myicon1 myicon2}
Create images for the two specified icons using image files in the "C:/myapp/Icons" folder.

icons create -group edit*
Create images for all icons with image filenames begining "edit" in the default folder.

icons create -file "C:/myapp/Icons" -group *blue*
Create images for all icons with image filenames containing "blue" in the "C:/myapp/Icons" folder.

icons create -file "C:/myapp/Icons" -group *
Create images for all icons in the "C:/myapp/Icons" folder.

Using Delete

icons delete {actreload16 navhome16}
Delete images for the two specified icons.

Using Query

NOTE: The default information is: ngts (name group type size)

Where the "file" identifies an ICONS library file:

icons query {actreload16 navhome16}
Return default information for the two specified icons...
{actreload16 action photo {16 16}} {navhome16 nav photo {16 16}}

icons query -file tkIcons.ikons {actreload16 navhome16}
Return default information for the two specified icons using the "tkIcons.ikons" library in the directory given by the "info library" command...
{actreload16 action photo {17 17}} {navhome16 nav photo {16 16}}

icons query -group connect
Return default information for all icons belonging to the "connect" group using the default library...
{connecting16 connect photo {16 16}} {connectno16 connect photo {16 16}} {connectyes16 connect photo {16 16}}

icons query -group connect -items ns
Return name and size information for all icons belonging to the "connect" group using the default library...
{connecting16 {16 16}} {connectno16 {16 16}} {connectyes16 {16 16}}


Where the "file" identifies a folder containing GIF/PNG image files:

icons query {myicon1 myicon2}
Return default information for the two specified icons...
{myicon1 N/A PNG {16 16}} {myicon2 N/A GIF {16 16}}

icons query -file "C:/myapp/Icons" {myicon1 myicon2}
Return default information for the two specified icon image files in the "C:/myapp/Icons" folder.
{myicon1 N/A PNG {16 16}} {myicon2 N/A GIF {16 16}}

icons query -file "C:/myapp/Icons" -group *blue
Return default information for all icons with image filenames ending "blue" in the "C:/myapp/Icons" folder.
{myicon1_blue N/A PNG {16 16}} {myicon2_blue N/A GIF {16 16}}

icons query -file "C:/myapp/Icons" -group *blue -items ns
Return name and size information for all icons with image filenames ending "blue" in the "C:/myapp/Icons" folder.
{myicon1_blue {16 16}} {myicon2_blue {16 16}}

Note: data and size information is only available for image files if the icon has already been created.


Copyright © 2013 Adrian Davis.