Tk Source Code

View Ticket
Login
Ticket UUID: cb077bea5b61898cd3c4b4ec997ecb509442dae7
Title: ttk::progressbar: configuring -value is ignored when -variable is set
Type: Bug Version: core-8-6-branch
Submitter: fvogel Created on: 2019-04-06 18:14:20
Subsystem: 88. Themed Tk Assigned To: fvogel
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2019-08-28 20:10:24
Resolution: Fixed Closed By: fvogel
    Closed on: 2019-08-28 20:10:24
Description:

The -value option of ttk::progressbar is not always updated when -variable is set

package require Tk
ttk::progressbar .pb -maximum 10 -variable {}
pack .pb
.pb configure -value 6
.pb cget -value          ; # expectedly returns 6
unset -nocomplain x
.pb configure -variable x
.pb configure -value 5
.pb cget -value          ; # expectedly returns 5
set y 2
.pb configure -variable y
.pb configure -value 4
.pb cget -value          ; # ??? unexpectedly returns value of y, i.e. 2
set y 1
.pb cget -value          ; # expectedly returns 1
.pb configure -variable {}
.pb configure -value 3
.pb cget -value          ; # expectedly returns 3

Reading the ttk::progressbar man page for -variable:

The name of a global Tcl variable which is linked to the -value. If specified, the -value of the progress bar is automatically set to the value of the variable whenever the latter is modified.

This is indeed true.

However, I think .pb configure -value xx should also set the linked variable (see example code above, at line marked with "???").

User Comments: fvogel added on 2019-08-28 20:10:24:
Merged to core-8-6-branch and trunk.

fvogel added on 2019-08-23 14:00:37:

After some thinking and more testing, I would say this is not a bug.

The ttk::progressbar man page says:

-value
The current value of the progress bar. [...] 

-variable
The name of a global Tcl variable which is linked to the -value. If specified, the -value of the progress bar is automatically set to the value of the variable whenever the latter is modified.

It is nowhere stated that the link between the variable and the value is bidirectional. And indeed it is not. When -variable is not empty:

* A change in the linked variable value will change the -value of the progressbar. This is specified and is actually observed.
* A change in the content of the -value option is NOT reflected in the linked variable. Therefore changing -value has actually no effect in the progressbar current value because right after the value was changed the value of the linked variable overwrites the -value given.

By looking at the source code, this is as-designed behavior: the value of the variable specified in -variable takes precedence over specification of -value.

This could be described a bit more clearly in the man page however, therefore I have added clarifications in [d6308b2684], for ttk::progressbar but also for ttk::scale (same situation). Moreover, I have checked that no other man page of any widget featuring -variable needs such clarification.

Note that one could perhaps change that designed behavior but I don't see a need here. Since ttk::progressbar has no set command, one way to set the value of a ttk::progressbar is to configure -value (whereas for, say, a scale widget it consists in calling the set command since scale has no -value option). When configuring the progressbar using -value, there is no point in setting -variable at the same time. Conversely, when configuring -variable and setting the progressbar value by setting this variable value, there is no point in doing the same at the same time through the -value option. So the progressbar value can be set using either -value or -variable (and setting that variable), but running both schemes at the same time does not really make sense.