1. Эта задача выполнима, не понял причины этого вопроса.
2. Я написал пример программы с счетчиком(как его использовать, понять не сложно)
import threading, sys
from pygame import *
font.init()
def thread(func):
def _sugar(*args) -> threading.Thread:
ret = threading.Thread(target = func, args = [*args,])
ret.start()
return ret
return _sugar
class Counter(object):
def __init__(s, w, h, bind, fg = Color(0, 255, 0), bg = Color(0, 0, 0),value=0, fnt = font.SysFont(None, 14)):
s.w,\
s.h,\
s.fg,\
s.bg,\
s.vl,\
s.fnt =\
w,h,fg,bg,value,fnt
s.bnd = bind
pass
def increase(s, step = 1):
s.vl += step
pass
def decrease(s, step = 1):
s.vl -= step
pass
def render(s):
ret = Surface((s.w, s.h), HWSURFACE|SRCALPHA)
ret.fill(s.bg)
ret.blit(transform.smoothscale(s.fnt.render(str(s.vl), 1, s.fg), ret.get_size()), (0, 0))
return ret
@thread
def bnd(s):
pass
pass
#
@thread
def bind(counter, event):
if event.type in (MOUSEBUTTONDOWN, MOUSEBUTTONUP):
counter.increase()
pass
pass
#
def main(argv):
display.init()
font.init()
sc = display.set_mode((800, 600), HWSURFACE|SRCALPHA)
counter = Counter(600, 400, bind, fnt = font.SysFont(None, 1024))
ticker = time.Clock()
target_FPS = 120
real_FPS = 0
while True:
ticker.tick(target_FPS)
real_FPS = ticker.get_fps()
for e in event.get():
if e.type == QUIT:
display.quit()
quit()
sys.exit()
pass
counter.bnd(counter, e)
pass
sc.fill((255,100,100))
sc.blit(counter.render(), (100, 100))
display.flip()
display.set_caption(f"Clicker based on counter [FPS: {int(real_FPS)}]")
pass
pass
if __name__ == '__main__':
main(sys.argv)
pass