Timer with arcade python


I wanted to make a visual timer in python but couldn't find any graphic libraries so I used arcade to do the job but I think there is something I'm not getting.
All I have so far :

import time
SCREEN_WIDTH = 600
SCREEN_HEIGHT = 600
arcade.open_window(SCREEN_WIDTH, SCREEN_HEIGHT, "Program test")
arcade.set_background_color(arcade.color.WHITE)
arcade.start_render()
mid_x = SCREEN_WIDTH/2
mid_y = SCREEN_HEIGHT/2
def cur_time(self): arcade.draw_text(str(c_tim),start_x,start_y,arcade.color.BLACK)
def sc(self): arcade.draw_rectangle_filled(mid_y,mid_y,600,600,arcade.color.BLACK) arcade.draw_rectangle_filled(mid_y,mid_y,600,600,arcade.color.WHITE)
start_x = 100
start_y = 100
c_tim = 10
while True: cur_time time.sleep(1) sc arcade.get_projection()
arcade.finish_render()
arcade.run()
2

2 Answers

Instead, you could use a Tkinter GUI for it. I don't have the time right now to code it for you, but arcade isn't designed for that kind of thing. It's for making 2D games generally not creating nice timers. Just use tkinter gui.

Simple timer with arcade:

import time
import arcade
import datetime
class Timer(arcade.Window): def __init__(self): super().__init__(600, 400, 'Arcade Timer') self.time = None def on_draw(self): arcade.start_render() if self.time: text = str(datetime.timedelta(seconds=time.time()-self.time)) else: text = 'Click to start timer!' arcade.draw_text(text, 300, 200, arcade.color.RED, 40, anchor_x='center') def on_mouse_release(self, x, y, button, key_modifiers): self.time = time.time() if not self.time else None
Timer()
arcade.run()

Example run:

enter image description here

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like