#campaign module for blunt wars
import pygame
import time
import sys
pygame.init()
size = [400, 400]
width = size[0]
height = size[1]
#colors
black = (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 colors
screen = pygame.display.set_mode((size), pygame.RESIZABLE)
pygame.display.set_caption('Blunt Wars - Campaign')
clock = pygame.time.Clock()
#updates screen res
for 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 textSurface
def 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.
我不知道为什么要这样做,但是如果有人可以帮助我,将不胜感激。
蝴蝶不菲
相关分类