Mal wieder ganz was wichtiges von mir

Code: Alles auswählen
from Tkinter import *
import time
def get_time_array():
l = []
for i in time.localtime()[3:6]:
for j in "%02i" % i:
l.append(int(j))
return l
def tick():
bits = [1,2,4,8]
t = get_time_array()
for x in range(6):
for y in range(4):
y1 = 3-y
if (t[x] & bits[y]) == 0: color = "blue"
else: color = "red"
c.itemconfigure("%s-%s" % (x,y1), fill=color)
def create_clock(event=None):
c.delete("all")
offset = 3
size_x = c.winfo_width() / 6 - offset
size_y = c.winfo_height() / 4 - offset -1
for x in range(6):
for y in range(4):
c.create_oval(
x*(size_x+offset)+offset,
y*(size_y+offset)+offset,
x*(size_x+offset)+offset+size_x,
y*(size_y+offset)+offset+size_y,
fill="blue",tags="%s-%s" % (x,y))
root = Tk()
c = Canvas(width=200, height=150, bg="black")
c.pack(fill=BOTH, expand=1)
c.bind("<Configure>", create_clock)
create_clock()
while 1:
tick()
root.update()
time.sleep(1)
root.mainloop()
Die Spalten sind von links nach rechts: 2 für die Stunden, 2 für die Minuten und 2 für ... na?

Die Zeilen von unten nach oben haben die folgenden Werte: 1, 2, 4, 8
Einfach die Zahlenwerte der roten Punkte zusammenzählen (jeweils für Stunden, Min.. ) und man hat die Uhrzeit.
Alles klar? Viel Spass damit

Gruß, mawe