I have a statement inside a while statement that is supposed to draw an image onto the canvas but it doesn't happen and I don't know why as it doesn't show any errors.
def buttonclick_gamescreen(event):
global scorecounter
global pressed
global randomimage
global images
pressed = ""
if event.x >853 and event.x <957 and event.y > 8 and event.y < 56 : pressed = 7
if event.x >666 and event.x <947 and event.y > 491 and event.y < 534 : pressed = 8
while pressed == 8 :
entryx = e1.get()
entryy = e2.get()
answerx = answerlistx[randomimage]
answery = answerlisty[randomimage]
print("The answer to X is", answerx, "You entered", entryx,"The answer to Y is", answery, "You entered ", entryy)
if entryx == answerx and entryy == answery:
print("correct")
canvas.delete(images)
randomimage = random.randrange(0,49+1)
scorecounter = scorecounter + 1
print("You score is now", scorecounter, "New random number is", randomimage)
game = PhotoImage(file=imagelist[randomimage])
images = canvas.create_image(30, 65, image = game, anchor = NW)
e1.delete(0, END)
e2.delete(0, END)
pressed = ''
else:
print("incorrect")
e1.delete(0, END)
e2.delete(0, END)
pressed = ''
The line images = canvas.create_image(30, 65, image = game, anchor = NW)
should work as it worked in another case for me.
Here's a link to the rest of the code since I don't want to make this question too long and messy, which shows where the canvas is drawn. http://pastebin.com/RxmPDUAD From my understanding right now I'll have to create a class and call the functions from there for this to work? EDIT: Having trouble still as I've tried using global variables and classes with no luck.
It's not a problem with the random number as I printed it just before the line the image is supposed to print from just incase it didn't work but it does. What am I doing wrong?