好吧,所以我使用pygame來創建程序,但是,當我嘗試創建我的矩形工具時,它似乎總是顯示TypeError:參數1必須是pygame.Surface,而不是builtin_function_or_method。我不知道爲什麼,因爲我問了一個同伴,它的工作非常好,使用相同的代碼。TypeError:參數1必須是pygame.Surface,而不是builtin_function_or_method(python 3.2.3)
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()
你能給我們完整的追溯? – jayelm
刺在黑暗中,你想要'screen.copy()'而不是'screen.copy'嗎? –
謝謝!事實證明,這正是LOL發生的事情。謝謝。 – user3142532