首页 > 解决方案 > Python misbehaving Weiredly? That too - Even while defining a Boolean?

问题描述

This is just a beginner in python, so my code is not that readable and not clean. But however, I wanted to know why I am getting an error.

import pygame
pygame.init()
pygame.font.init()

# Colors
yellow = (250, 250, 100)
brown = (50, 0, 15)
pink = (224, 7, 184)
white = (250, 250, 250)

# Vairables
screen = pygame.display.set_mode()
heading_text = pygame.font.SysFont("Comic Sans MS", 42)
heading_text_surface = heading_text.render('Time Table', True, (0, 0, 0))
today_text = pygame.font.SysFont("Comic Sans MS", 42)
today_text_surface = today_text.render('Today', True, (250, 250, 250))
tommorow_text = pygame.font.SysFont("Comic Sans MS", 42)
tommorow_text_surface = tommorow_text.render('Tommorow', True, (250, 250, 250))
all_days_text = pygame.font.SysFont("Comic Sans MS", 42)
all_days_text_surface = all_days_text.render('All Days', True, (250, 250, 250))
maths_text1 = pygame.font.SysFont("Comic Sans MS", 42)
maths_text1_surface = maths_text1.render('Maths', True, (255, 255, 255))
zero_hour = pygame.font.SysFont("Comic Sans MS", 42)
zero_hour_surface = zero_hour.render('Zero Hour', True, (0, 153, 255))
time_120to150 = pygame.font.SysFont("Comic Sans MS", 36)
time_120to150_surface = time_120to150.render('1:20PM to 1:50PM', True, (('Zero Hour', True, (0, 153, 255))))


running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
    
    screen.fill(yellow)
    pygame.draw.rect(screen, brown, (52, 75, 1800, 75))
    screen.blit(heading_text_surface, (800, 10))
    screen.blit(today_text_surface, (95, 85))
    screen.blit(tommorow_text_surface, (295, 85))
    screen.blit(all_days_text_surface, (570, 85))
    pygame.draw.rect(screen, pink, (52, 250, 700, 130))
    pygame.draw.rect(screen, pink, (52, 475, 700, 130))
    pygame.draw.rect(screen, pink, (52, 700, 700, 130))
    pygame.draw.rect(screen, pink, (52, 925, 700, 130))
    screen.blit(maths_text1_surface, (73, 264))
    screen.blit(time_120to150_surface, (90, 264))

    pygame.display.flip()

Error: Why running = True is wrong?

Again, just a beginner so I don't have that experience in this. Why I'm I getting a Syntax Error, but running = True is right. Please help me with this problem.

标签: pythonpygameboolean

解决方案


尝试将之前的行更改running = True为:

time_120to150_surface = time_120to150.render('1:20PM to 1:50PM', True, ('Zero Hour', True, (0, 153, 255)))

我删除了一组额外的括号。


推荐阅读