是否可以随时更改TextBox文本颜色?我已经尝试过Google;我的问题看起来微不足道,但我仍然茫然。

TextBox方法:

: dir(matplotlib.widgets.TextBox)
Out[63]:
[
 ...
 'active',
 'begin_typing',
 'connect_event',
 'disconnect',
 'disconnect_events',
 'drawon',
 'eventson',
 'get_active',
 'ignore',
 'on_submit',
 'on_text_change',
 'position_cursor',
 'set_active',
 'set_val',
 'stop_typing']


AxesWidget超类方法:

: dir(matplotlib.widgets.AxesWidget)
Out[64]:
[
 ...
 'active',
 'connect_event',
 'disconnect_events',
 'drawon',
 'eventson',
 'get_active',
 'ignore',
 'set_active']


没有暗示。至少在我看来。

最佳答案

仅部分回答-不知道完整的应用程序是否对您有帮助。您可以更改2种文本的颜色:标签和编辑框。下面显示了如何一次更改每个。

import matplotlib.widgets
import matplotlib.pyplot as plt

plt.figure(1)
ax = plt.subplot(111)
tb = matplotlib.widgets.TextBox(ax, "Name:", initial="Jane Doe")
tb.label.set_color('red')      # label color
tb.text_disp.set_color('blue') # text inside the edit box


如果只希望标签文本不同,那么该问题仍然存在。但是,只要更改了编辑框(text_disp)中的文本,该文本将再次变为黑色。
这是因为小部件会重新创建文本
by removing and then re-generating,它将再次变为黑色。

source for the text create method没有用户可以修改的任何参数(颜色,字体大小/粗细等)或包含为TextBox实例属性。

您可以编写自己的覆盖此方法的子类。还是在输入文本后简单设置就足够了?

关于python - matplotlib.widgets.TextBox:更改颜色,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49423770/

10-12 17:50
查看更多