I'm trying to make a GUI for the game of Tic Tac Toe using Matplotlib. So far, I've made an array of buttons which change their labels to "X" when clicked:
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import Button
def callback(event, button):
print button
button.label.set_text("X")
fig, axarr = plt.subplots(3,3, figsize=(6,6))
buttons = [[None for _ in range(3)] for _ in range(3)]
for i in range(3):
for j in range(3):
buttons[i][j] = Button(ax=axarr[i][j], label="")
buttons[i][j].on_clicked(lambda event, i=i, j=j: callback(event, buttons[i][j]))
axarr[i][j].set_aspect('equal')
fig.tight_layout(h_pad=0, w_pad=0)
plt.show(block=False)
This produces a plot like this:
where I have already clicked all the buttons except one. What I notice when using this GUI, however, is that the new label only becomes visible after I move my mouse off the button, whereas I would like the change to happen immediately. Any ideas how to make this happen?