samedi 18 avril 2015

Image not displaying on tkinker button in python

I'm attempting to display an image on a button when clicked. I'm doing this with a handler that worked fine changing the text on a button but when I display an image the button re-sizes but doesn't display the image. Here is the handler for the button:



#generic handler for all game buttons
#
#Paramters:
# button = the button that was clicked
# player = an int list of 1 representing the current player(X=0,O=1)
#
#changes the image of the button to X or O depending on player
#and changes player to whoever's turn is next
def gameHandler(button, player):
xImage= PhotoImage(file = 'X.gif')
oImage = PhotoImage(file = 'O.gif')
if player[0] == 1:
button['image'] = xImage
player[0] = 0
else:
button['image'] = oImage
player[0] = 1


Both of the files exist in the same directory and are named correctly. I'm not sure why they aren't displaying. After some googleing I've learned that there is sometimes a scope problem but I can't see how that applies here. Any help is really appreciated!


Aucun commentaire:

Enregistrer un commentaire