# clock.py By Anton Vredegoor (anton.vredegoor@gmail.com)
# last edit: july 2009,
# license: GPL
# enjoy!
"""
A very simple clock.
The program transforms worldcoordinates into screencoordinates
and vice versa according to an algorithm found in: "Programming
principles in computer graphics" by Leendert Ammeraal.
"""
from Tkinter import *
from time import localtime
from datetime import timedelta,datetime
import sys, types, os
_inidle = type(sys.stdin) == types.InstanceType and \
sys.stdin.__class__.__name__ == 'PyShell'
class transformer:
def __init__(self, world, viewport):
self.world = world
self.viewport = viewport
class clock:
def __init__(self,root,deltahours = 0):
self.world = [-1,-1,1,1]
self.bgcolor = '#ffffff'
self.timecolor = '#000000'
self._ALL = 'all'
self.pad = 25
self.root = root
WIDTH, HEIGHT = 200, 200
root.bind("<Escape>", lambda _ : root.destroy())
self.delta = timedelta(hours = deltahours)
self.canvas = Canvas(root,
width = WIDTH,
height = HEIGHT,
background = self.bgcolor)
viewport = (self.pad,self.pad,WIDTH-self.pad,HEIGHT-self.pad)
self.T = transformer(self.world,viewport)
self.root.title('Clock')
self.canvas.bind("<Configure>",self.configure())
self.canvas.pack(fill=BOTH, expand=YES)
self.poll()
def configure(self):
self.redraw()
def redraw(self):
sc = self.canvas
sc.delete(self._ALL)
width = sc.winfo_width()
height =sc.winfo_height()
sc.create_rectangle([[0,0],[width,height]], fill = self.bgcolor, tag = self._ALL)
viewport = (self.pad,self.pad,width-self.pad,height-self.pad)
self.T = transformer(self.world,viewport)
self.paintgrafics()
def paintgrafics(self):
self.painthms()
def painthms(self):
sc = self.canvas
T = datetime.timetuple(datetime.utcnow()-self.delta)
x,x,x,h,m,s,x,x,x = T
#self.root.title('%02i:%02i:%02i' %(h,m,s))
now = datetime.now()
curTime = now.strftime('%H:%M:%S')
workTime = now-startTime;
sc.create_text(100,10,fill="black",text="NOW :"+curTime)
sc.create_text(100,30,fill="orange",text="START:"+startTime.strftime('%H:%M:%S'))
if (workTime.seconds > 5) :
sc.create_text(100,50,fill="magenta",text="Go to HOME!!")
if (workTime.seconds > 8) :
sc.create_text(100,70,fill="magenta",text="15,000!!")
def poll(self):
self.configure()
self.root.after(200,self.poll)
def main():
root= Tk()
global startTime
startTime = datetime.now()
clock(root,deltahours = -9)
if not _inidle:
root.mainloop()
if __name__=='__main__':
main()
'Python' 카테고리의 다른 글
Macbook Catalina Python 개발 환경 잡기 (0) | 2020.11.28 |
---|---|
Python 연습 프로젝트 1 (0) | 2020.11.28 |
Mac에서 Python 개발 환경 구축하기 (0) | 2016.02.18 |
import (0) | 2016.02.08 |
functions (0) | 2016.02.08 |