Hi. I've just registered, but I'm not exactly new to here (i've been lurking as a guest). I'm trying to make a countdown timer based on a class that I created, which accepts hours, minutes, and seconds as parameters and counts them down to zero, will displaying them in a Tkinter window.
Now, I did start on it using Tkinter, but the Tkinter window just never appears (for some reason, I suspect this has something to do with the time.sleep() i use in my aggregate function, because everything else seems fine and when I the aggregate() function call, the window runs normally.
I managed to create a temporary fix using livewires, that instead of using time.sleep(), uses the mainloop() cycles to decide when to decrement a second (mainloop in livewires do a certain amount of cycles per second). The problem with this is that it isn't always accurate. That is, sometimes it goes too fast, and sometimes it goes too slow with the exact same FPS settings (I suspect this has to do with my CPU load or something...i'm not very skilled and I don't know a lot about these things).
Another problem with the livewires method is that while in Tkinter, I could just destroy() the timer window when the timer is through and call back the main window(I want the timer to quit, and open back the start screen when it is through), with this livewires version it just locks up when i tell it screen.quit() (The destroy() function only wipes all the objects off. Heres the code (so sorry for lack of commenting...i was supposed to comment it last night, but got sidetracked and now im at work and dont have much time. I'll add comments if you cant understand the code):
#Te-je Rodgers #Counter module from livewires import games, color class Counter(games.Sprite): """My counter is a sprite.""" def __init__(self, screen, x, y,image, passer): self.screen = screen self.init_sprite(screen = screen, x = x, y = y, image=image) self.name=passer timer=passer self.hh=timer self.mm=timer self.ss=timer self.count=0 self.col=color.blue games.Text(screen=screen, x=200, y=20, text=self.name, color = color.white, size=50) games.Text(screen=screen, x=200, y=180, text="Press ENTER or F1 to stop", color=color.white, size=20) self.display_message() def close_timer(self): if self.hh<0: import last else: self.screen.quit() def good(self): x=0 def display_message(self): games.Message(screen = self.screen, x=200, y=100, text=str(self.hh)+" : "+str(self.mm)+" : "+str(self.ss), size=100, after_death=self.good(), color=self.col, lifetime=75) def decrease_seconds(self): self.ss-=1 if self.hh>=0: if self.ss<0: self.ss=59 self.mm-=1 if self.mm<0: self.mm=59 self.hh-=1 if self.hh<0: self.close_timer() else: self.display_message() else: self.display_message() else: self.display_message() def moved(self): self.count+=1 if self.screen.is_pressed(games.K_RETURN) or self.screen.is_pressed(games.K_F1) or self.screen.is_pressed(games.K_KP_ENTER): self.close_timer() if self.hh==0 and self.mm==0 and self.ss==6: self.col=color.red if self.count==75: self.decrease_seconds() self.count=0 def start(passer): root32=games.Screen(400, 200) sprite_image=games.load_image("img.bmp") back=games.load_image("box2.jpg") root32.set_background(back) x=Counter(root32, 296, 139, sprite_image, passer) root32.mainloop(50)
the parameter "passer" in in this format:
("string",(int_hh, int_mm, int_ss))