gpt4 book ai didi

python - matplotlib.widgets.TextBox : change color

转载 作者:太空宇宙 更新时间:2023-11-04 02:30:09 24 4
gpt4 key购买 nike

有没有办法随时更改 TextBox 文本颜色?我已经试过谷歌了;我的问题看起来太琐碎了,但我仍然一头雾水。

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 父类(super class)方法:

: 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 : change color,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49423770/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com