현재 Python 2.7.5 및 pygame을 사용하여 작성중인 페인트 프로그램의 저장 기능을 만들려고합니다. 오류 메시지는 다음과 같은 코드에서 발생하기 때문에 나는 위의 코드에 문제가 있다고 생각하지 않습니다Python의 함수 문제 저장
from pygame import *
from random import *
from glob import *
from math import *
def getName():
ans = "" # final answer will be built one letter at a time.
arialFont = font.SysFont("Times New Roman", 16)
back = screen.copy() # copy screen so we can replace it when done
textArea = Rect(5,5,200,25) # make changes here.
pics = glob("*.bmp")+glob("*.jpg")+glob("*.png")
n = len(pics)
choiceArea = Rect(textArea.x,textArea.y+textArea.height,textArea.width,n*textArea.height)
draw.rect(screen,(220,220,220),choiceArea) # draw the text window and the text.
draw.rect(screen,(0,0,0),choiceArea,1) # draw the text window and the text.
for i in range(n):
txtPic = arialFont.render(pics[i], True, (0,111,0)) #
screen.blit(txtPic,(textArea.x+3,textArea.height*i+choiceArea.y))
typing = True
while typing:
for e in event.get():
if e.type == QUIT:
event.post(e) # puts QUIT back in event list so main quits
return ""
if e.type == KEYDOWN:
if e.key == K_BACKSPACE: # remove last letter
if len(ans)>0:
ans = ans[:-1]
elif e.key == K_KP_ENTER or e.key == K_RETURN :
typing = False
elif e.key < 256:
ans += e.unicode # add character to ans
txtPic = arialFont.render(ans, True, (0,0,0)) #
draw.rect(screen,(220,255,220),textArea) # draw the text window and the text.
draw.rect(screen,(0,0,0),textArea,2) #
screen.blit(txtPic,(textArea.x+3,textArea.y+2))
display.flip()
screen.blit(back,(0,0))
return ans
: 여기 내 코드는 다음
if saveRect.collidepoint(mx,my):
txt = getName(True)
image.save(screen.subsurface(canvas),txt)
오류 메시지입니다 내가 얻을 :
Traceback (most recent call last):
File "C:\Users\Wisdom1\Desktop\Comp Science Files\Canvas_(2).py", line 276, in <module>
txt = getName(True)
TypeError: getName() takes no arguments (1 given)
누군가이 오류로 나를 도울 수 있다면 크게 감사하겠습니다. 어떤 도움을 주셔서 감사합니다. 감사합니다
왜 코드를 올바르게 추가하지 않았습니까? 오류가 발생한 부분의 나머지 코드는 무엇입니까, 어떻게 '이미지'가 정의됩니까? –