8000 Modify matplotlib TextBox value without triggering callback · Issue #14226 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
Modify matplotlib TextBox value without triggering callback #14226
Closed
@justinblaber

Description

@justinblaber

For example, I have a Slider with a callback set via on_changed(). I have the option of modifying the Slider value with set_val() without triggering the callback by setting eventson to False before setting the value.

However, if I set eventson to False for the TextBox, then update the value with set_val(), the callback on_submit() still gets triggered.

The source code for my version of Matplotlib verifies this:

For TextBox:

def set_val(self, val):
    newval = str(val)
    if self.text == newval:
        return
    self.text = newval
    self.text_disp.remove()
    self.text_disp = self._make_text_disp(self.text)
    self._rendercursor()
    self._notify_change_observers()
    self._notify_submit_observers()

For Slider:

def set_val(self, val):
    """
    Set slider value to *val*

    Parameters
    ----------
    val : float
    """
    xy = self.poly.xy
    xy[2] = val, 1
    xy[3] = val, 0
    self.poly.xy = xy
    self.valtext.set_text(self.valfmt % val)
    if self.drawon:
        self.ax.figure.canvas.draw_idle()
    self.val = val
    if not self.eventson:
        return
    for cid, func in self.observers.items():
        func(val)

Is there a preferred way to do this?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0