How to change the text through code in matplotlib TextBox widget

Viewed 3954

I have a matplotlib widget Textbox as follows

temp_descr = 'wow'
self.axLabel = plt.axes([0.7, 0.05, 0.21, 0.075])
self.text_boxLabel = TextBox(self.axLabel, 'Label: ', temp_descr)

Once it is set to its initial value, how can I later change the text? Like

temp_descr = 'new wow'
self.text_boxLabel.set_text(temp_descr)

However, this gives the following error

AttributeError: 'TextBox' object has no attribute 'set_text'

2 Answers

In case anyone is wondering how to do it the "wrong" way, here it is:

textbox.text = "foo, bar and baz"

This will update the display without updating the internal state, which could be useful to mock the "initial" functionality. Just beware that it will introduce some hard to find inconsistencies.

Related