好的,所以我使用pygame创建程序,但是,当我尝试创建我的矩形工具时,它似乎总是显示TypeError:参数1必须是pygame.Surface,而不是builtin_function_or_method。我不确定为什么,因为我向同行询问了它,并且使用相同的代码完全正常。
from pygame import *
from random import *
screen = display.set_mode((1152,864))
start = 0,0
color = (0,0,0)
canvasRect = Rect(150,160,850,700)
recttoolRect = Rect(20,350,40,40)
draw.rect(screen,(255,255,255),canvasRect)
running = True
while running:
finish = False
for e in event.get():
if e.type == QUIT:
running = False
if e.type == MOUSEBUTTONDOWN:
if e.button == 1:
start=e.pos
copy = screen.copy
mb = mouse.get_pressed()
mx,my = mouse.get_pos()
draw.rect(screen,(255,255,255),recttoolRect)
if mb[0] == 1 and recttoolRect.collidepoint(mx,my):
tool = rect
if mb[0] == 1 and canvasRect.collidepoint(mx,my) and tool == rect:
screen.set_clip(canvasRect)
screen.blit(copy,(0,0))
draw.rect(screen,(colour),(start[0],start[1],mx-start[0],my-start[1]))
display.flip()
quit()
答案 0 :(得分:0)
如果没有完整的回溯,很难说,但我猜你已经忘记了某个函数调用后面的一些括号。例如。如果rect
是一个函数,则可能需要编写rect()
,而不是rect
。