python - 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.
解决方案
尝试将之前的行更改running = True
为:
time_120to150_surface = time_120to150.render('1:20PM to 1:50PM', True, ('Zero Hour', True, (0, 153, 255)))
我删除了一组额外的括号。
推荐阅读
- python - 抓取数据推特时语法无效?
- android - 限制 Flutter 中特定用户的 FCM 通知
- python - 试图用python矩阵中的索引切片来理解语法
- c# - 当用户单击一个数据表的一行时,如何使用数据库中的数据显示另一个数据表?
- php - 无法清除缓存 - “Class App\Console\Kernel 不存在”错误
- spring - 何时在 Spring 应用程序中使用 @Configuration 和 @Component?
- ruby-on-rails - 为什么将每个 do 语句的输出放在 RoR 中的视图助手中时会有所不同?
- mysql - 无法更改表以添加外键?
- java - 基于对象文本的 Java 游戏帮助(初学者)
- c - 是否可以使用纯winsock捕获以太网帧