Tkinter自动刷新

时间:2011-05-28 16:11:47

标签: python refresh tkinter clock tk

  

可能重复:
  Tkinter: How to make Tkinter to refresh and delete last lines?

试图回答我的问题,但没有一个帮助..

问题是:Tkinter中的时钟指针闪烁,因为我使用了w.delete,但是如果我不使用它,那么时钟指针复制..请帮助:)

import Tkinter as tk; import time
from math import cos,sin,pi
import sys
root=tk.Tk(); root.title("Clock")
w = tk.Canvas(root, width=320, height=320, bg="#456", relief= "sunken", border=10)

w.pack()

size=300
def funA():

    s=time.localtime()[5]
    m=time.localtime()[4]
    h=time.localtime()[3]

    degrees = 6*s
    angle = degrees*pi*2/360
    ox = 165
    oy = 165
    x = ox + size*sin(angle)*0.45
    y = oy - size*cos(angle)*0.45
    t = w.create_line(ox,oy,x,y, fill = "#ffc")

    degrees1 = 6*m
    angle1 = degrees1*pi*2/360
    ox1 = 165
    oy1 = 165
    x1 = ox1 + size*sin(angle1)*0.4
    y1 = oy1 - size*cos(angle1)*0.4
    t1 = w.create_line(ox1,oy1,x1,y1, fill = "Red", width=6)


    degrees2 = 30*h
    angle2 = degrees2*pi*2/360
    ox2 = 165
    oy2 = 165
    x2 = ox2 + size*sin(angle2)*0.2
    y2 = oy2 - size*cos(angle2)*0.2
    t2 = w.create_line(ox2,oy2,x2,y2, fill = "Black", width=8)
    w.update()
    root.after(200,funA)
    w.delete(t1)

root.after(1500, funA)  
uzr1 = tk.Label(root, text="12", bg="#456" )
uzr1.place(x=160, y=13)
uzr2 = tk.Label(root, text="6", bg="#456" )
uzr2.place(x=160, y=303)
uzr3 = tk.Label(root, text="3", bg="#456" )
uzr3.place(x=310, y=160)
uzr4 = tk.Label(root, text="9", bg="#456" )
uzr4.place(x=11, y=160)

def Quit():
    root.after(700,root.destroy())


e = tk.Button(root,text="Quit", command=Quit)
e.pack()
root.mainloop()

如果我用funA w.delete(t)写,那么时钟二手闪烁,如果不是那么它复制.. 所以这是所有时钟指针..

  • t是二手
  • t1是Minute hand
  • t2是时针

0 个答案:

没有答案