# jtkversion.tcl

## Introduction

The jtkversion.tcl library is distributed as part of the jstools package. It consists of procedures to make it easier to write scripts that will work under both Tk 3 and Tk 4.

This document describes jtkversion.tcl version 4.1/4.4.

## Usage

### Accessing the Library

In order to use the jtkversion.tcl library, it (and any other libraries it depends on) must be in your Tcl `auto_path`, described in `tclvars`(n). Information about how to arrange that, and other conventions common to the jstools libraries, is in the Usage section of The jstools Libraries.

## Credits and Copyright

### Author

Jay Sekora
`js@aq.org`
`http://www.aq.org/~js/`

### Copyright

The library is copyright © 1992-1995 by Jay Sekora, but may be freely redistributed under the conditions at the top of the file.

## Overview

### Procedures

`j:tk4` - perform an action (or return true) if running under Tk version 4 or greater
`j:tk3` - perform an action (or return true) if running under Tk version 3 or earlier
`j:tkversion` - perform an action (or return true) under a given range of Tk versions

### See Also

jtkutils.tcl

## j:tk4

### Usage

`j:tk4` [command]

### Description

This procedure executes command (in the calling procedure's stack frame) if and only if running under Tk version 4 or later. It returns `1` if the command was executed (i.e., if the version of Tk it's running under is 4 or greater) and 0 otherwise. If command is omitted, no action is performed, but the return value still indicates what version of Tk is being used.

## j:tk3

### Usage

`j:tk3` [command]

### Description

This procedure executes command (in the calling procedure's stack frame) if and only if running under Tk version 3 or earlier. It returns `1` if the command was executed (i.e., if the version of Tk it's running under is 3 or less) and 0 otherwise. If command is omitted, no action is performed, but the return value still indicates what version of Tk is being used.

## j:tkversion

### Usage

`j:tkversion` op`` number`` [command]
or
`j:tkversion range {`low`` high`}` [command]

### Arguments

op is a Tcl relational operator, like `<=`, `==`, `>`, or `!=`
number, low, and high are Tk version numbers
command is a Tcl command to execute under the given Tk version range

### Examples

`j:tkversion < 4 {
puts stderr \x07
}
j:tkversion >= 4 {
bell -displayof .
}
j:tkversion < 4 {
j:alert -text \
"Warning: File can't be saved under this version of Tk."
}
j:tkversion range {4.0 4.1} {
set file [j:fs]
}
j:tkversion > 4.1 {
set file [tk_getOpenFile]
}
j:tkversion < 4.0 {
j:alert -text "Wrong Tk version; requires at least 4.0"
}
if {[string length [info commands makeImage]] ||
[j:tkversion >= 4.0]} {
labelWithImage $label
}
`

### Description

In the first form of the command (without `range`), this procedure executes command (in the caller's context) and returns `1` (true) if and only if the Tcl expression `{$tkversion` op`` number`}` evaluates to true (where `$tk_version` is the version number of Tk the script is executing under).

In the second form (with `range`), this procedure executes command (in the caller's context) and returns `1` (true) if and only if the current version of Tk is between low and high, inclusive.

In both forms, command can be omitted, in which case the only effect is returning `1` or `0`; this can be useful in expressions.

## Bugs and Misfeatures

- All these procedures are really misfeatures. :-)

`
`