Tk Source Code

View Ticket
Login
Ticket UUID: b54adf47963db5824b5e4725dc692c2c5b7e28e5
Title: -validatecommand of ttk::entry returns true, still the entry is invalid
Type: Bug Version: >= 8.6.10
Submitter: anonymous Created on: 2024-01-19 13:47:02
Subsystem: 07. [entry] Assigned To: nobody
Priority: 5 Medium Severity: Minor
Status: Open Last Modified: 2024-01-20 06:37:38
Resolution: None Closed By: nobody
    Closed on:
Description:
At switching entries with Tab key, the 1st entry is highlighted as invalid (red border),
though its validate command comV1 returns "true".

The problem is due to "update" in comV1 and "set ::v1 new" in comV2.


  puts "Tk [package require Tk]"
  ttk::style theme use alt

  proc comV1 {} {
    update ;#  <<<-------------- a bug of ttk?
  #  update idletasks
    puts [incr ::run]:V1
    return true
  }

  proc comV2 {} {
    set ::v1 new ;#  <<<-------------- a bug of ttk?
    return true
  }
  #_______________________

  set imgbas {iVBORw0KGgoAAAANSUhEUgAAABQAAAAUBAMAAAB/pwA+AAAAD1BMVEX////MzMz6+vrIyMjo6Oho
  eOB0AAAAJklEQVQI12MQhAMGAQYIUGBkEGGAAkYGIQRTYBAwDQgpEBSGeQgAPjgCz8y34ZwAAAAA
  SUVORK5CYII=}
  set imginv {iVBORw0KGgoAAAANSUhEUgAAABQAAAAUBAMAAAB/pwA+AAAAIVBMVEUAAAD/////AAD/4+P/UFD/
  SUn/Dg7/DQ3/U1P/EBD/ERGgIWSjAAAAAXRSTlMAQObYZgAAADpJREFUCNdjYHBXAoMSBgZOJSiY
  wOAULAgGphoMRYYQprAag5IgFCgNHBPhHCRHIpy+gIHBDcLKYAAAFroVKMt+DDMAAAAASUVORK5C
  YII=}
  set boxbas [image create photo -data $imgbas]
  set boxinv [image create photo -data $imginv]
  ttk::style element create Entry.field image [list $boxbas invalid $boxinv] -border 5
  #_______________________

  set v1 [set v2 {}]
  pack [ttk::entry .e1 -textvar ::v1 -validate focus -validatecom ::comV1] -padx 2 -pady 2
  pack [ttk::entry .e2 -textvar ::v2 -validate focus -validatecom ::comV2] -pady 2
  pack [ttk::button .b1 -text "Change v1" -command ::comV2] -pady 2
  pack [ttk::treeview .t1 -height 2 -columns {C1} -displaycolumns {C1}] -pady 2
  pack [listbox .l1 -height 2] -pady 2
  .t1 insert {} end -values item1
  .t1 insert {} end -values item2
  .l1 insert end item1
  .l1 insert end item2
  bind .t1 <<TreeviewSelect>> {puts seltree; ::comV2}
  bind .l1 <<ListboxSelect>> {puts selbox; ::comV2}

  focus .e1
User Comments: anonymous added on 2024-01-20 06:37:38:
The listbox do not invalidate 1st entry too.

anonymous added on 2024-01-20 06:18:29:
Also, I added ttk::treeview.

Try switching:
 - from 1st entry to 2nd entry (click 2nd entry)
 - from 1st entry to the button (click the button)
 - from 1st entry to the treeview (click the treeview's item)

Switching to the button goes without the invalidation. Other two make the 1st entry invalid.

At that, "update" command does not spawn any special side effects, in this specific example.
Indeed it does nothing here, except for invalidating 1st ttk::entry.

anonymous added on 2024-01-20 05:47:43:
Yes, update is evil, generally said. But not everywhere.

I've found this issue absolutely by accident, when trying rdbende themes https://wiki.tcl-lang.org/page/rdbende.

Sincerely, I don't understand why some widgets influence here while others not.

See the updated code above - I added the button that does the same as 2nd entry, i.e. changing ::v1 variable, but without the issue in question.

oehhar added on 2024-01-19 16:03:18:

Hi,

please allow me to write "update is evil".

It is IMHO very bad style to have an update in a validate function, as, within update, anything may happen. If you have any further processing, please start it with "after idletasks".

The red border you are talking about is the created image?

If I run your script, I get:

% ttk::style element create Entry.field image [list $boxbas invalid $boxinv] -border 5
Duplicate element Entry.field

I suppose, this only works for a certain theme. A, prefixing your script with:

ttk::style theme use alt
and the effect is visible. I allowed me to edit the ticket.

The red border is neat !

You may dig into the ttk code and find out what is going on. But I think, if you put "update" in a script you can break any callback by certain circumstances.

Take care, Harald