5

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 2

6

You do not only want to set the text which is shown but also change the text which is internally stored. To do this all at once use the TextBox's .set_val() method.

import matplotlib.pyplot as plt
import matplotlib.widgets

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

textbox.set_val("jojojo")

plt.show()
Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.