How to change the text through code in matplotlib TextBox widget

后端 未结 2 1441
天命终不由人
天命终不由人 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()
    

提交回复
热议问题