Tk Source Code

View Ticket
Login
Ticket UUID: 2358545
Title: spinbox formatting has side effect
Type: Bug Version: obsolete: 8.5.8
Submitter: jack_r Created on: 2008-11-29 10:40:03
Subsystem: 17. [spinbox] Assigned To: aku
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2026-09-27 19:41:51
Resolution: Fixed Closed By: jan.nijtmans
    Closed on: 2026-09-27 19:41:51
Description:
If a spinbox is formatted with -format %02.0f, when we decrease with arrow we pass from 09 to 00 and when increasing with arrow, it is never possible to go above 09 if we start below 09. If already above 10 and increasing, it works.

Below sample code works with Tk 8.4.19 but failed with Tk 8.5 (ActiveTcl 8.5.5, Debian Lenny 8.5.3, eTcl 8.5.2 or 8.5.5)

package require Tk

set versions ""
lappend versions "Tcl: $tcl_patchLevel"
lappend versions "Tk : $tk_patchLevel"
label .l -text [join $versions \n]
pack .l

set second 15
spinbox .sb -from 0 -to 59 \
  -format %02.0f -width 2 -textvariable second
pack .sb
User Comments: jan.nijtmans added on 2026-09-27 19:41:51:

Fixed (again) [8ebff84d765ca1b3|here]


serhiy.storchaka added on 2026-09-24 08:22:25:

The same octal problem came back on core-8-6-branch with the fix for [9e89324a0a], which replaced sscanf() with Tcl_GetDouble() again. That regression is tracked in [9e89324a0a] and fixed on spinbox-octal-86. The remaining reason to keep this ticket open, a public Tcl API for decimal-only parsing, no longer applies to 9.x, where leading zeros are not octal. I suggest closing it as Fixed.


dgp added on 2011-06-08 04:17:04:
Fix merged to trunk.

Leaving open at reduced prio so we can consider
creating the Tcl_* routines to better support this sort of thing.
Either public access to TclParseNumber() or some Tcl_Scan*()
sort of thing along the lines of Tcl_Format*().

dgp added on 2011-06-08 04:07:04:
Fixed for Tk 8.5.10 replacing Tcl_GetDouble() calls
with sscanf( "%lf").

dgp added on 2010-05-10 21:32:53:
now that I see the comment that ttk::spinbox
does not have this failure, I wonder how many
of these redesign ideas are already in place
in that?

dgp added on 2010-05-10 21:29:03:
jenglish beat me to it.

Trouble is that the spinbox widget
takes pains to conceptually treat the
value as a double while actually storing
it as a string, with full sprintf() - Tcl_GetDouble()
round trip on every change.

The implicit assumption is that every -format 
choice produces a string that can be re-parsed
again as a double.  The unified number parser
in Tcl 8.5 does not do that since it consistently
treats "08" as not a double as well as not an integer.

After that the remaining behavior is explained by the
spinbox behavior that any attempt to set to a value
that is not a double will cause reset to the -from value.

The long term solution for this particular example
is Kill Octal.

The question raised is whether there are any
other -format values that lead to the same
problem where the generated string is no
longer a valid Tcl double.  If so, then I think
the design of spinbox needs reconsideration,
which might be a good idea anyway.  The
effort taken to force storage of a double in
string form is certainly not what I expected.

For a more limited focus on just fixing the
bug, perhaps a call to TclParseNumber()
ought to be used rather than Tcl_GetDouble().
Then the flag TCL_PARSE_DECIMAL_ONLY
could be employed to control the parsing.  It
appears to me that only decimal is used for
spinbox values.  Can someone confirm?

If TclParseNumber() is the right tool, this is
evidence that we ought to make it public
in 8.6 so that Tk 8.6 can continue to use
only public interfaces of Tcl.

jenglish added on 2010-05-09 05:34:47:
This is, of course, The Octal Problem.

Internally the spinbox calls Tcl_GetDouble() on the string value.   In 8.4 Tcl_GetDouble just called strtod() (which does not suffer from the octal bug), in 8.5 it uses the TIP#249 facilities (which, alas, does).

Reassigning to kbk for guidance -- what is the proper way for Tcl client code to get the equivalent of strtod() nowadays?

teopetuk added on 2010-05-09 02:01:28:
By the way, ttk::spinbox works fine in 8.6b1.

dgp added on 2010-05-09 01:13:25:
This looks bad; is it a simple fix or at least
diagnosis among the Tk gurus?

teopetuk added on 2010-05-08 12:04:00:
The same bug is present in 8.6b1.