How to change the text through code in matplotlib TextBox widget

后端 未结 2 1420
天命终不由人
天命终不由人 2021-01-23 02:57

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, \         


        
相关标签:
2条回答
  • 2021-01-23 03:29

    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()
    
    0 讨论(0)
  • 2021-01-23 03:34

    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.

    0 讨论(0)
提交回复
热议问题