python - 变量语法错误
问题描述
所以这:
import pygame
import time
import random
import sys
itworks = True
pygame.init()
screen = pygame.display.set_mode((600, 600))
bootpng = pygame.image.load('bootimage.png')
bootpng = pygame.transform.scale(bootpng, (600, 600))
backgroundmenu = pygame.image.load('Menu_background.png')
backgroundmenu = pygame.transform.scale(backgroundmenu, ((600, 600))
button = pygame.image.load('technical_information_button')
button = pygame.transform.scale(infobut, ((130, 80))
screen.blit(bootpng, (0, 0))
time.sleep(3)
while itworks == True:
screen.blit(backgroundmenu, (0, 0))
screen.blit(tekbutton, (470, 520))
for event in pygame.event.get():
if ecent.type == pygame.QUIT:
itworks = False
# if event.type == pygame.MOUSEBUTTONDOWN:
# Set the x, y postions of the mouse click
#x, y = event.pos
#if ball.get_rect().collidepoint(x, y):
pygame.display.flip()
pygame.quit()
是我的代码。Buuut .. 出于某种原因,python 在变量按钮第 15 行*处说“无效语法”。我真的不知道该怎么办,我尝试了很多东西,所以我希望我能从这里得到帮助:D
解决方案
您需要删除一个额外的括号。
代替:button = pygame.transform.scale(infobut, ((130, 80))
和:button = pygame.transform.scale(infobut, (130, 80))
在 Python 中,应该始终有一个左括号和右括号。
编辑:
只是补充一下,我强烈建议将您替换while itworks == True
为while itworks is True
. 更多信息可以在这里看到:布尔标识 == True vs is True
基本上,if
由于不比较引用的相等性,该语句在某些情况下可能不会给出预期的结果。这只是“pythonic”的做事方式。
推荐阅读
- spring - 如何测试是否具有给定 id 属性的给定链接使用 mockMvc、.andExpect() 和 xpath?
- vue.js - 尽管事件显示在开发工具中,但 Vue 中的 addEventListener 没有触发
- java - 如何从 Android 的后台线程更新 UI 元素?
- javascript - 事件侦听器之间的状态未按预期更新
- javascript - 使用 jquery 输入后查找具有特定类的跨度
- r - 将时间间隔绘制为段
- javascript - 链接多个级别的条件承诺
- reactjs - Webpack:使用 DefinePlugin 和 DotEnv 未定义的 process.env
- c# - C# AWS Lambda 函数异常处理
- gitlab - 如何禁用一种类型的所有服务集成