Tk Source Code

View Ticket
Login
Ticket UUID: d25b721f68bfb6ae3ccfced8912a971cc6d7f576
Title: Division by zero in the ttk::scale widget's "get x y" command
Type: Bug Version: all
Submitter: nemethi Created on: 2025-07-13 12:55:48
Subsystem: 88. Themed Tk Assigned To: nobody
Priority: 5 Medium Severity: Severe
Status: Closed Last Modified: 2025-07-14 17:20:25
Resolution: Fixed Closed By: nemethi
    Closed on: 2025-07-14 17:20:25
Description:

The ttk::scale widget's  get x y  command generates an error message if the widget was resized to become so small that the trough is no longer visible, as demonstrated with the aid of the following simple script:

ttk::style theme use clam       ;# optional
pack [ttk::frame .f] -expand yes -fill both
pack [ttk::scale .f.scl] -padx 9p -pady 9p -fill x

Start the script and decrease the window's width until the scale's trough disappears and only the slider remains visible.  Now drag the slider with the mouse and try to move it horizontally.  As a result, a message like the following poppes up in an error dialog:

floating point value is Not a Number
floating point value is Not a Number
    while executing
"$w set [$w get $x $y]"
    (procedure "ttk::scale::Drag" line 4)
    invoked from within
"ttk::scale::Drag .f.scl 16 3 "
    (command bound to event)

The error is caused by a division by zero in the PointToValue() function of the file generic/ttk/ttkScale.c.

The attached diff output fixes the bug by avoiding the division by zero in a similar way as the TkScalePixelToValue() function of the file generic/tkScale.c.

User Comments: nemethi (claiming to be Csaba Nemethi) added on 2025-07-14 17:20:25:

Many thanks, Harald!

I have merged the fix to all three branches; see the commits [86b98d2c], [b3393952], and [f172bb47].


oehhar added on 2025-07-14 10:13:57:

Thanks Csaba,

on WIndows, the minimum toplevel size is to high, so need more spacing:

pack [ttk::frame .f] -expand yes -fill both
pack [ttk::scale .f.scl] -padx 90p -pady 9p -fill x

Patch now in Commit [723fe552] starting branch [d25b721f-ttk-scale-division-zero].

Bug reproducible and bugfix works for me.

If anybody may review, please just merge, my review is finished. If a wizard may construct a test case, even better.

Thanks, Csaba, for all ! Harald


Attachments: