zoukankan      html  css  js  c++  java
  • 用Python的Tkinter实现时钟

    import Tkinter,sys,time
    root=Tkinter.Tk()
    root.minsize(500, 500)
    Label1=Tkinter.Label(text=time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())))
    Label1.pack()
    def trickit():
        currentTime=time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
        Label1.config(text=currentTime)
        root.update()
        Label1.after(1000, trickit)
    Label1.after(1000, trickit)
    
    root.mainloop()

    在实现过程中,有几点要注意的地方:

    1.config函数注意test不能写成‘text’,之前写成Label1.config('text'=currentTime)就一直不对。

    2.本来还想使用root.bind('<这里不知道些什么>',trickit),最后也没找到办法。具体可以看这个博客了解Event的用法:http://blog.sina.com.cn/s/blog_ac9fdc0b0101n642.html

      这个也行:http://blog.sina.com.cn/s/blog_ac9fdc0b0101n9u6.html

    3.应该记住这个算法,在trickit函数中隔一秒钟调用自己一次达到时钟的效果。!!!!!!!!!!!!!!!!!!!

  • 相关阅读:
    网络编程 TCP
    网络编程之 osi七层协议
    面向对象之元类,单例
    面向对象之异常处理
    面向对象之多态
    面向对象之封装
    mysql 单表查询
    mysql 行(记录)的详细操作
    mysql 库表的操作
    数据库初识
  • 原文地址:https://www.cnblogs.com/wangjiyuan/p/pythonshizhong.html
Copyright © 2011-2022 走看看