我有一个带有图像的 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()
Run Code Online (Sandbox Code Playgroud)
事件处理程序被调用,但图像未更改。有人知道如何在构建后更改 matplotlib 按钮小部件的图像吗?