使用tkinter编写gui,threading处理指针动画,源码如下
import tkinter as tk # Python 3
import math
import get_time as gt
import re
import threading
root = tk.Tk()
def createWidgets():
CANVAS_WIDTH = 200
CANVAS_HEIGHT = 200
root.canvas = tk.Canvas(root,width=CANVAS_WIDTH, height=CANVAS_HEIGHT, highlightthickness=0,bg='green')
root.canvas.pack()
circle(root.canvas, CANVAS_WIDTH / 2, CANVAS_WIDTH / 2, CANVAS_WIDTH / 2 - 10, 'SlateGray')
circle(root.canvas, CANVAS_WIDTH / 2, CANVAS_WIDTH / 2, CANVAS_WIDTH / 2 - 16, 'DarkSlateGray')
circle(root.canvas, CANVAS_WIDTH / 2, CANVAS_WIDTH / 2, CANVAS_WIDTH / 2 - 18, 'white')
time = gt.get_time()
root.h = int(re.match('\d+-\d+-\d+ (\d+):\d+:\d+.*', time['datetime']).group(1))
root.m = int(re.match('\d+-\d+-\d+ \d+:(\d+):\d+.*', time['datetime']).group(1))
root.s = int(re.match('\d+-\d+-\d+ \d+:\d+:(\d+).*', time['datetime']).group(1))
timer_h = threading.Timer(1, paint_h)
timer_h.start()
root.canvas.bind(sequence="<B1-Motion>", func=processMouseEvent)
root.canvas.bind(sequence="<Button-1>", func=getMouseLocation)
root.canvas.bind(sequence="<ButtonRelease-1>", func=resetMouseLocation)
root