#campaign module for blunt warsimport pygameimport timeimport syspygame.init()size = [400, 400]width = size[0]height = size[1]#colorsblack = (0,0,0)white = (255,255,255)red = (200,0,0)green = (0,200,0)blue = (0,0,255)bright_red = (255,0,0)bright_green = (0,255,0)#end colorsscreen = pygame.display.set_mode((size), pygame.RESIZABLE)pygame.display.set_caption('Blunt Wars - Campaign')clock = pygame.time.Clock()#updates screen resfor event in pygame.event.get(): if event.type ==pygame.VIDEORESIZE: screen = pygame.display.set_mode((event.w, event.h), pygame.RESIZABLE)text = pygame.font.SysFont('Arial', 30)def text_objects(text, font): textSurface = font.render(text, True, black) return textSurfacedef button(msg,x,y,w,h,ic,ac,action=None): mouse = pygame.mouse.get_pos() click = pygame.mouse.get_pressed() if x+y > mouse[0] > x and y+h > mouse[1] > y: pygame.draw.rect(screen, ac,(x,y,w,h)) if click[0] == 1 and action != None: action() else: pygame.draw.rect(screen, ic,(x,y,w,h)) smallText = pygame.font.Sysfont('Arial',20) textSurf, TextRect = text_objects(msg, smallText) textRect.center = ( (x+(w/2)), (y+(h/2)) ) screen.blit(textSurf, TextRect)def intro(): intro = True while intro: for event in pygame.event.get(): #print(event) if event.type == pygame.QUIT: pygame.quit() quit() #import Blunt_Wars因此,这是我的整个程序,我试图制作一个主菜单,但是当我运行此代码时,出现此错误:textSurf, textRect = text_objects("Blunt Wars - Campaign", header)TypeError: 'pygame.Surface' object is not iterable.我不知道为什么要这样做,但是如果有人可以帮助我,将不胜感激。
2 回答
蝴蝶不菲
TA贡献1810条经验 获得超4个赞
调查一下:
def text_objects(text, font):
textSurface = font.render(text, True, black)
return textSurface
textSurf, textRect = text_objects("Blunt Wars - Campaign", header)
text_objects()返回结果font.render()是一个pygame.Surface实例。
这不是迭代的,这就是为什么您的拆箱无法正常进行的原因...
添加回答
举报
0/150
提交
取消