Skip to content
Tcl Source Code History Of Ticket ce6b428620dd89bc
Login

History Of Ticket ce6b428620dd89bc

Artifacts Associated With Ticket ce6b428620dd89bc

  1. Ticket change [f9f56d4a7a] (rid 197761) by GOLosinas on 2022-02-10 02:40:25:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/plain"
    4. comment initialized to:
      I am using a ttk.Spinbox to capture some number and I want to display a messagebox once the value in the spinbox reaches the limit. I bound the spinbox to the <code> <<Increment>> </code> event to perform a check, and display the message but the event is endlessly triggered once you close the messagebox. I made a small application to illustrate the issue.
      
      class App(Tk):
          def __init__(self):
              super().__init__()
              self.title('Sample')
              self.geometry('300x100')
              Selector(self).pack()
      
      class Selector(ttk.Frame):
              def __init__(self, container):
                  super().__init__(container)
                  self.max_length = 10
                  self.input = IntVar(0)
                  self.check_length_calls = 0
                  
                  self.label = ttk.Label(self, text="Quantity: ").pack()
                  self.spinbox = ttk.Spinbox(self, from_=0,
                                             to=10,
                                             textvariable=self.input)
                  self.spinbox.pack()
                  self.spinbox.bind('<<Increment>>', lambda e: self.check_length(e))
      
                  ttk.Button(self, text="print func calls", command= self.print_check_length_calls).pack()
      
      
              def check_length(self, e):
                  self.check_length_calls += 1
                  if str(self.spinbox) != str(self.focus_get()):
                      return
                  if self.input.get() == self.max_length:
                      messagebox.showwarning("Max length reached", "Too long!")               
                      self.focus_set()
      
              def print_check_length_calls(self):
                  print(self.check_length_calls)
              
              
      if __name__ == "__main__":
          app = App()
          app.mainloop()
      
    5. foundin initialized to: "TkVersion 8.6"
    6. is_private initialized to: "0"
    7. login: "GOLosinas"
    8. priority initialized to: "5 Medium"
    9. private_contact initialized to: "18ce5dcbd56fb12aaee69b84ea192d8d353caf30"
    10. resolution initialized to: "None"
    11. severity initialized to: "Important"
    12. status initialized to: "Open"
    13. submitter initialized to: "GOLosinas"
    14. subsystem initialized to: "02. Event Loops"
    15. title initialized to:
      <<Increment>> event is endlessly triggered once messagebox closes
      
    16. type initialized to: "Bug"
  2. Ticket change [8f8dae8ff0] (rid 197762) by fvogel on 2022-02-10 07:21:58:

    1. icomment:
      Thank you for your report. Please note that this is the Tcl tracker, not the Tk tracker. If the issue gets confirmed this ticket should be closed and reopened in the [https://core.tcl-lang.org/tk/reportlist|Tk tracker].
      
      Furthermore your code seems to be in Python. What I <i>believe</i> is the equivalent Tcl/Tk code is as follows:
      
      <verbatim>
      package require Tk
      set max_length 10
      set check_length_calls 0
      set input 0
      proc check_length {} {
        global check_length_calls max_length
        incr check_length_calls
        if {[focus] ne ".t.s"} {return}
        if {[.t.s get] == $max_length} {
          puts "Too long"
        }
      }
      toplevel .t
      wm geometry .t 300x100
      ttk::label .t.l -text "Quantity: "
      ttk::spinbox .t.s -from 0 -to 10 -textvariable input
      bind .t.s <<Increment>> {check_length}
      ttk::button .t.b -text "Print fun calls" -command {puts $check_length_calls}
      pack .t.l .t.s .t.b
      </verbatim>
      
      But with this code I fail to reproduce the problem you describe.
      
    2. login: "fvogel"
    3. mimetype: "text/x-fossil-wiki"
  3. Ticket change [4ce9c0a803] (rid 198153) by chrstphrchvz on 2022-02-16 09:58:59:

    1. icomment:
      The reporter may likely need to provide more information; what is the output of <tt>Tk().getvar('tk_patchLevel')</tt> and <tt>Tk().tk.eval('tk windowingsystem')</tt>?
      
      I ran the Tkinter example (need to do <tt>from tkinter import *; from tkinter import ttk, messagebox</tt> first) and did not observe the reporter's issue for Tcl/Tk 8.6.12 on X11. However if I tweak Francois' Tcl example to resemble the reporter's Tkinter a little more (no separate toplevel, show a messagebox, focus on the spinbox afterward):
      
      <pre>
      package require Tk
      set max_length 10
      set check_length_calls 0
      set input 0
      proc check_length {} {
        global check_length_calls max_length
        incr check_length_calls
        if {&#91;focus&#93; ne ".s"} {return}
        if {&#91;.s get&#93; == $max_length} {
          tk_messageBox -title "Max length reached" -message "Too long!" -icon warning
          focus .s
        }
      }
      wm geometry . 300x100
      ttk::label .l -text "Quantity: "
      ttk::spinbox .s -from 0 -to 10 -textvariable input
      bind .s &lt;&lt;Increment&gt;&gt; {check_length}
      ttk::button .b -text "Print fun calls" -command {puts $check_length_calls}
      pack .l .s .b
      </pre>
      
      …then I do observe that every time the messagebox is dismissed, another will appear shortly. But I wonder if this behavior is intentional/as documentation would suggest, and just something Tk programs need to beware.
      
    2. login: "chrstphrchvz"
    3. mimetype: "text/x-fossil-wiki"
  4. Ticket change [c7dfca3cee] (rid 198155) by fvogel on 2022-02-16 10:37:24:

    1. icomment:
      Christopher's script below triggers the reported problem on Windows 10, with Tk 8.6.9, or core-8-6-branch, or main.
      
    2. login: "fvogel"
    3. mimetype: "text/plain"
  5. Ticket change [58164e9f27] (rid 198334) by fvogel on 2022-02-18 20:59:00:

    1. assignee changed to: "fvogel"
    2. icomment:
      Trimmed down script allowing to reproduce the issue on Windows (at least):
      
      <verbatim>
      package require Tk
      pack [ttk::spinbox .s]
      bind .s <<Increment>> {tk_messageBox -message "Message!"}
      # and click on the up arrow
      </verbatim>
      
    3. login: "fvogel"
    4. mimetype: "text/x-fossil-wiki"
  6. Ticket change [e4f32f878b] (rid 198335) by fvogel on 2022-02-18 21:20:20:

    1. icomment:
      The problem is due to the following. When clicking the up arrow of the spinbox, an <<Increment>> virtual event is generated from ttk::spinbox::Press. This event is repeatedly generated:
      
      <code>ttk::Repeatedly event generate $w <<Increment>></code>
      
      ttk::Repeatedly runs its provided script (<code>event generate $w <<Increment>></code>) and after this script returns schedules a repeated run of this same script. The order of what is happening here is important.
      
      This re-scheduling repeats until the up arrow button is released (mouse button up), at which time ttk::spinbox::Release gets called, which calls ttk::CancelRepeat to, well... cancel the repeat!
      
      This implementation allows to increment repeatedly the spinbox value by pressing and maintaining the up arrow down. Incrementation starts when pushing down the mouse button on the up arrow, and it stops when releasing the mouse button.
      
      Now, with this implementation, when the script bound to <code>event generate $w <<Increment>></code> includes instructions that allow the event loop to run before the script returns, the ttk::CancelRepeat call from the mouse button release will run from inside the bound script instead of after this script has finished. Since the Repeat(timer) value that is used to identify what needs to be cancelled is only set AFTER the return of the bound script, the cancel call will have no effect.
      
      The fix therefore is to swap the order of script execution and repetition scheduling, see [fb9a363237].
      
    2. login: "fvogel"
    3. mimetype: "text/x-fossil-wiki"
    4. resolution changed to: "Fixed"
  7. Ticket change [1b5d620f27] (rid 198336) by fvogel on 2022-02-18 21:22:34:

    1. icomment:
      The fix obviously is in the Tk repository:
      
      [https://core.tcl-lang.org/tk/info/fb9a3632373e63e3]
      
      The present ticket should have been opened there btw.
      
    2. login: "fvogel"
    3. mimetype: "text/x-fossil-wiki"
  8. Ticket change [70a618d52d] (rid 198535) by fvogel on 2022-02-25 23:25:20:

    1. closedate changed to: "2459636.47593332"
    2. closer changed to: "fvogel"
    3. icomment: "Merged in core-8-6-branch and trunk (of Tk)."
    4. login: "fvogel"
    5. mimetype: "text/plain"
    6. status changed to: "Closed"