Python Pygame:font.render()给出;TypeError:无效的前景RGBA参数";
我尝试使用Python Pygame:font.render()给出;TypeError:无效的前景RGBA参数";,python,pygame,screen,blit,Python,Pygame,Screen,Blit,我尝试使用screen.blit()创建一个总点击量栏(我还希望它在单击时更新文本),我尝试了 但它不起作用 line 21, in <module> text = font.render('Your total clicks are',totalbal, True, WHITE) TypeError: Invalid foreground RGBA argument 您必须连接字符串 text=font.render('您的总点击量为'+str(totalbal),Tru
screen.blit()
创建一个总点击量栏(我还希望它在单击时更新文本),我尝试了
但它不起作用
line 21, in <module>
text = font.render('Your total clicks are',totalbal, True, WHITE)
TypeError: Invalid foreground RGBA argument
您必须连接字符串
text=font.render('您的总点击量为'+str(totalbal),True,白色)
或者使用
text=font.render(您的总点击量为{totalbal}',True,白色)
如果文本发生更改,则需要再次渲染文本:
text=font.render(您的总点击量为{totalbal}',True,白色)
while循环:#主游戏循环
# [...]
对于pygame.event.get()中的事件:
如果event.type==MOUSEBUTTONDOWN:#检测鼠标点击
总BAL+=cps
text=font.render(如果“您的总点击次数为{totalbal}”,则为True,白色)
# [...]
它会在您退出并登录时更新,但我希望它每次都会更新
line 21, in <module>
text = font.render('Your total clicks are',totalbal, True, WHITE)
TypeError: Invalid foreground RGBA argument
import pygame, sys, time
from pygame.locals import *
pygame.init()
WHITE = 255,255,255
font = pygame.font.SysFont(None, 44)
baltotal = open("totalbal.txt", "r+")
totalbal = int(baltotal.read())
w = 800
h = 600
screen = pygame.display.set_mode((w,h))
Loop = True
text = font.render('Your total clicks are',totalbal, True, WHITE)
while Loop: # main game loop
...
if event.type == MOUSEBUTTONDOWN: #detecting mouse click
totalbal += cps
print("Your total clicks are", totalbal, end="\r")
...
screen.blit(text, (235,557))
pygame.display.flip()
pygame.display.update()
clock.tick(30)
with open("totalbal.txt", "w") as baltotal:
baltotal.write(str(totalbal))
baltotal.close
pygame.quit()
sys.exit()