def keyPressed():
global fill_r
global fill_v
global rect_x
if key == 'W' or key == 'w':
fill_rect()
print("TEST")
这是我的代码的一部分,将无法正常工作我在用python处理3中做到了
如果要从上一个问题(How to fix loading bar stopping before the end)开始进度条,请按w,然后必须添加状态(start_progress
)。按下键时设置状态(start_progress = True
)并根据状态运行fill_rect
:
from time import sleep
def fill_rect():
global fill_r, fill_v, rect_x, speed_fill
fill(fill_r, fill_v, 0)
rect(width/2 - 100, height/2 - 12.5, rect_x, 25)
if rect_x <= 200:
rect_x = min(200, rect_x + speed_fill)
speed_fill += 1
fill_r += 5
fill_v -= 2
def setup():
global fill_r, fill_v, rect_x, speed_fill, start_progress
fill_r, fill_v, rect_x, speed_fill = 25, 100, 0, 0
start_progress = False
size(500, 500)
def draw():
background(0, 100, 255)
fill(0)
rect(width/2 - 100, height/2 - 12.5, 200, 25)
if start_progress:
fill_rect()
def keyPressed():
global start_progress
if key == 'W' or key == 'w':
start_progress = True
print("TEST")