我想几天前,同一份文件确实有效。我很困惑,希望有人能帮助我。 这是我的代码,如果可以忽略变量名称,我是德国人:
import pygame
screenbreite = 800
screenhöhe = 500
farbe1 = (220, 220, 220)
farbe2 = (220, 220, 220)
farbe3 = (220, 220, 220)
SCHWARZ = (0, 0, 0)
kastenabstand = 95
kastenlänge = 170
kastenhöhe = 80
Thema = "nichts"
pygame.init()
screen = pygame.display.set_mode((screenbreite, screenhöhe))
schrift = pygame.font.SysFont("Franclin Gothic Demi, Segoe UI", 20)
bernoulliformelkastentext = schrift.render("Bernoulliformel", True, SCHWARZ)
erwartungswertkastentext = schrift.render("Erwartungswert", True, SCHWARZ)
kumuliertkastentext = schrift.render("Kumuliert", True, SCHWARZ)
mausposition = pygame.mouse.get_pos()
pygame.mouse.get_pos
pygame.mouse.set_pos(400, 250)
MAUSTASTE_GEDRÜCKT = pygame.mouse.get_pressed()
clock = pygame.time.Clock()
done = False
def kastentest () :
x = (mausposition[1])
y = (mausposition[4])
xliegtdrauf = False
yliegtdrauf = False
xtief = 50
xhoch = 220
ytief = 50
yhoch = 130
if x > xtief and x < xhoch :
xliegtdrauf = True
if y > ytief and y < yhoch :
yliegtdrauf = True
if xliegtdrauf == True and yliegtdrauf == True :
Thema = "bernoulli"
xliegtdrauf = False
xtief = 315
xhoch = 385
if x > xtief and x < xhoch :
xliegtdrauf = True
if xliegtdrauf == True and yliegtdrauf == True :
Thema = "erwartung"
xliegtdrauf = False
xtief = 580
xhoch = 750
if x > xtief and x < xhoch :
xliegtdrauf = True
if xliegtdrauf == True and yliegtdrauf == True :
Thema = "kumuliert"
while done == False :
for event in pygame.event.get() :
while Thema == "nichts" :
screen.fill((255, 255, 255))
pygame.draw.rect(screen, farbe1, pygame.Rect(50, 50, kastenlänge, kastenhöhe)) #Bernoulliformelkasten
pygame.draw.rect(screen, farbe2, pygame.Rect((kastenabstand+50+kastenlänge), 50, kastenlänge, kastenhöhe)) #Erwartungkasten
pygame.draw.rect(screen, farbe3, pygame.Rect((2*kastenabstand+50+2*kastenlänge), 50, kastenlänge, kastenhöhe)) #Kumuliertkasten
screen.blit( bernoulliformelkastentext, (70, 75))
screen.blit( erwartungswertkastentext, (70+kastenabstand+kastenlänge, 75))
screen.blit( kumuliertkastentext, (70+2*kastenabstand+25+2*kastenlänge, 75))
if event.type == pygame.QUIT:
done = True
if Thema == "bernoulli" or Thema == "erwartung" or Thema == "kumuliert" :
screen.fill((255, 0, 0))
pygame.display.flip()
clock.tick(30)
如果有人能告诉我这个“mausposition[1]”是否正确地得到变量“mausposition”的第二个字符,那就太好了
你的游戏循环搞砸了。应该是这样的:
否则,应用程序将永远卡在嵌套的
while
循环中;因此,不处理事件会导致窗口变得无响应那没有道理
mausposition
将是一个整数元组,因为您调用了mausposition = pygame.mouse.get_pos()
。因此mausposition[1]
将是鼠标光标相对于行运行时窗口的y位置(在本例中,在脚本开始处)mausposition[4]
将抛出一个IndexError
,因为元组只有两个项:x和y坐标相关问题 更多 >
编程相关推荐