#3032 ttk::entry fails with not-yet-set -textvariable

closed-wont-fix
5
2012-11-08
2012-11-06
No

package require Tk
pack [entry .e -textvariable yourtext] -expand yes -fill x
pack [button .b -command Doit -text "Press"]
proc Doit {} {
variable yourtext
tk_messageBox -message "You pressed, text is $yourtext"
}

Runs as expected, but the same script with ttk (as shown in the
example):

package require Tk
pack [ttk::entry .e -textvariable yourtext] -expand yes -fill x
pack [ttk::button .b -command Doit -text "Press"]
proc Doit {} {
variable yourtext
tk_messageBox -message "You pressed, text is $yourtext"
}

Throws an error, if there is no text in the entry:
can't read "yourtext": no such variable
while executing
"tk_messageBox -message "You pressed, text is $yourtext""
(procedure "Doit" line 3)
invoked from within
"Doit"
invoked from within
".b invoke "
invoked from within
".b instate !disabled { .b invoke } "
invoked from within
".b instate pressed { .b state !pressed; .b instate !disabled { .b
invoke } } "
(command bound to event)

% info patchlevel
8.5.11
% parray tcl_platform
tcl_platform(byteOrder) = littleEndian
tcl_platform(machine) = x86_64
tcl_platform(os) = Linux
...

Discussion

  • Donal K. Fellows

    • labels: 104343 --> 88. Themed Tk
    • assigned_to: nobody --> jenglish
    • summary: checkbutton: Incorrect behavior of TTK vs TK --> ttk::entry fails with not-yet-set -textvariable
     
  • Joe English

    Joe English - 2012-11-08
    • status: open --> closed-wont-fix
     
  • Joe English

    Joe English - 2012-11-08

    This is one of the areas where ttk::* widgets are intentionally different from the corresponding core widgets. Core widgets are somewhat inconsistent wrt linked -variables and -textvariables (compare behaviour of [entry] and [label] widgets for example). ttk::* widgets try to use a consistent policy:

    * If there is a linked variable (non-empty -variable or -textvariable option), then the value of the variable always takes precedence.
    * If the linked variable does not exist, the value is interpreted as the empty string (possibly with an additional state change)
    * ttk::* widgets only write to the linked -variable in response to user actions or by explicit widget commands (e.g., checkbutton 'invoke' method). In particular, [$w configure -variable V] will _not_ write to the variable V.