【发布时间】:2018-03-25 18:10:02
【问题描述】:
我有一个带有图像的 matplotlib 按钮小部件。单击按钮后,我想将图像更改为其他内容。我试过这个:
import matplotlib
matplotlib.use('TkAgg')
import matplotlib.image as mpimg
import matplotlib.pyplot as plt
from matplotlib.widgets import Button
FIGURE = plt.figure()
ICON_PLAY = mpimg.imread('./ui/images/play.png')
ICON_PAUSE = mpimg.imread('./ui/images/pause.png')
def play(event):
print "Starting"
start_button.image = ICON_PAUSE
start_button = Button(plt.axes([0.1, 0.1, 0.8, 0.8]), '', image=ICON_PLAY)
start_button.on_clicked(play)
plt.show()
事件处理程序被调用,但图像没有改变。有人知道如何在构建后更改 matplotlib 按钮小部件的图像吗?
【问题讨论】:
-
也许您实际上并不需要图像,而是使用一些箭头左右作为标签,
Button(ax, label=ur'$\u25B6$'),如this answer 所示。
标签: python image button matplotlib