캔버스에 이미지를 그리기로되어있는 while 문 안에 문이 있지만 상황이 발생하지 않습니다. 이유는 모르겠지만 오류가 나타나지 않습니다. .파이썬 - 이미지가 캔버스에 그려지지 않습니다.
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 = ''
라인 images = canvas.create_image(30, 65, image = game, anchor = NW)
은 나를 위해 다른 경우에 효과가 있습니다.
다음은 캔버스가 그려지는 곳을 보여주는이 질문을 너무 길고 지저분하게하고 싶지 않으므로 나머지 코드에 대한 링크입니다. http://pastebin.com/RxmPDUAD 지금 당장은 클래스를 만들고 거기에서 함수를 호출해야합니다. EDIT : 운이없는 전역 변수와 클래스를 사용해 보았지만 여전히 문제가 있습니다.
난이도가 문제가되지 않습니다. 단지 이미지가 인쇄되기 직전에 인쇄 된 것처럼 작동하지 않지만 작동하지 않습니다. 내가 도대체 뭘 잘못하고있는 겁니까?
당신이 주회 돌이를 입력되는 것을 방지하기 위해
PhotoImage
Frame
바인딩 할self
키워드를 사용할 수 있습니까? 당신이 할 때까지 아무런 일도 일어나지 않을 것입니다. 모든 작업은 본질적으로 대기 상태에 있으며, 메인 루프는 작업 대기열을 통해 실행되며 모든 작업, 프로세스 이벤트 등을 수행합니다. – GP89그게 무슨 뜻인지는 모르겠지만 그렇지 않다고 추측합니다. 그 말을 올려 주셔서 감사합니다. – ThatsNotMyName
어쨌든'canvas.mainloop()'를 호출하고 있습니까? (당신이 제공 한 코드에는 없지만 정의되지 않은 기호가 있기 때문에 모든 코드가 아닌 것 같습니다.) – GP89