如何改变按键显示的号码



我正在尝试制作一个可以倒数时间的时钟,但我被卡住了,因为我不知道如何改变时钟上的数字(例如当我按下"+ 1分钟"&;按钮时钟从0:0到1:0变化),我是新的蟒蛇和蟒蛇,所以我希望得到一些信息,我将能够理解。这是我的代码:

import pygame
pygame.init()
screen = pygame.display.set_mode((500,600))
GREEN 
YELLOW
BLACJ
RED
WHITE
KIARA
Text_1 = font_1.render('+',True,KIARA)
Text_2 = font_1.render('+',True,KIARA)
Text_3 = font_1.render('-',True,KIARA)
Text_4 = font_1.render('-',True,KIARA)
Text_5 = font_1.render('START',True,BLACK)
Text_6 = font_1.render('RESET',True,BLACK)
total_secs = 0
mins = int(total_secs/60)
secs = int(total_secs%60)
time = f"{mins}:{secs}"
Text_time = font_2.render(time,True,BLACK)
TextRect_time = Text_time.get_rect()
TextRect_time.center = (248,425)

running = True
while running:
screen.fill(GREEN)
mouse_x, mouse_y = pygame.mouse.get_pos()
screen.blit(Text_1,TextRect_1)
screen.blit(Text_2,TextRect_2)
screen.blit(Text_3,TextRect_3)
screen.blit(Text_4,TextRect_4)
screen.blit(Text_5,TextRect_5)
screen.blit(Text_6,TextRect_6)
screen.blit(Text_time,TextRect_time)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False

if event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 1:
if (70 < mouse_x < 130) and (70 < mouse_y < 130):
if (170 < mouse_x < 230) and (70 < mouse_y < 130):
if (70 < mouse_x < 130) and (220 < mouse_y < 280):
if (170 < mouse_x < 230) and (220 < mouse_y < 280):
pygame.display.flip()
pygame.quit()

每次按下一个键时,都需要更改文本并重新呈现文本表面。例如:

if (70 < mouse_x < 130) and (70 < mouse_y < 130):
mins = (mins+1) % 60
time = f"{mins}:{secs}"
Text_time = font_2.render(time, True, BLACK)

相关内容

  • 没有找到相关文章

最新更新