[Edu-sig] Programming for the fun of it

Michal Wallace sabren@manifestation.com
Tue, 12 Dec 2000 09:16:50 -0500 (EST)


On 12 Dec 2000, Jeffrey Elkner wrote:

> One last thing.  I think we need to develop and on-line library
> of cool little programs like this that show Python's usefullnes.
> 
> I would be glad to set up this library if folks would send me
> example programs.  To be truely useful to classroom teachers
> they should meet the following criteria:
> 
> 1. They should be short enough to be looked at and discussed
> in 5 to 10 minutes.
> 
> 2. In keeping with 1 above they should use algorithms that
> are fairly easy to understand.
> 
> 3. They should transparent Python, with minimal use of
> special purpose libraries.


I use this one all the time, to pace myself when working out:



from Tkinter import *
import time

def currentTime(start):
    return "%02i:%02i"  % time.localtime(time.time() - start)[4:6]

class Clock(Frame):
    def showTime(self, *args):
        self.text.configure(text = currentTime(self.start))
        self.after(10, self.showTime)

    def __init__(self, master=None):
        Frame.__init__(self, master)
        Pack.config(self) #??
        self.start = time.time()
        self.text = Label(self, {"text": currentTime(self.start),
                                 "font": (('Verdana'), 40)})
        self.text.pack()
        self.after(10, self.showTime)


clock  = Clock()
clock.mainloop()




Cheers,

- Michal
------------------------------------------------------------------------
www.manifestation.com  www.sabren.com  www.linkwatcher.com  www.zike.net
------------------------------------------------------------------------