参考资料:

An Introduction To Tkinter

Python 定时器

Python实例讲解 -- 定时播放 (闹钟+音乐)

Python Tkinter之Label

#coding=utf8

import threading,time,Tkinter,tkFont

class Timer(threading.Thread):
def __init__(self,fn,args=(),sleep=0,lastDo=True):
threading.Thread.__init__(self)
self.fn = fn
self.args = args
self.sleep = sleep
self.lastDo = lastDo
self.setDaemon(True) self.isPlay = True
self.fnPlay = False def __do(self):
self.fnPlay = True
apply(self.fn,self.args)
self.fnPlay = False def run(self):
while self.isPlay :
time.sleep(self.sleep)
self.__do() def stop(self):
#stop the loop
self.isPlay = False
while True:
if not self.fnPlay : break
time.sleep(0.01)
#if lastDo,do it again
if self.lastDo : self.__do() top=Tkinter.Tk()
ft=tkFont.Font(root=top,family = ('sans-serif'), size = 10)
#ft=tkFont.Font(root=top,size = 13)
#ft=None
top.title("Promodoro")
LEFT, Label = Tkinter.LEFT, Tkinter.Label # shortcut names
frame = Tkinter.Frame(top)
frame.pack(fill=Tkinter.X, side=Tkinter.BOTTOM)
label_line = Tkinter.Frame(frame, relief=Tkinter.RAISED, borderwidth=1)
label_line.pack(side=Tkinter.TOP, padx=2, pady=1)
Label(label_line, text=u"Today's tomato(es):", width=20, anchor="w", font=ft).pack(side=LEFT) num = Tkinter.StringVar()
num_label = Label(label_line, textvariable=num, anchor="e", width=2, font=ft)
num.set("0")
num_label.pack(side=LEFT) Label(label_line, text=u" | ", width=1, font=ft).pack(side=LEFT)
Label(label_line, text=u" time left: ", width=14, anchor="w", font=ft).pack(side=LEFT)
Label(label_line, text=u"25m16s", width=8, anchor="e", font=ft).pack(side=LEFT) num_label.bind("<Button-1>",lambda event:num.set(str(event.x))) top.mainloop()

python和tk实现桌面番茄时间(1)的更多相关文章

  1. [转载]番茄时间管理法(Pomodoro Technique):一个番茄是如何让你工作更有效率的

    如果你经常读一些关于提高工作效率或时间管理类的博客,一定听说过番茄时间管理法(Pomodoro Technique).这是一种极好的帮助你集中注意力.获得更高工作效率的方法. 基本上,它的实施方法是这 ...

  2. #使用parser获取图片信息,输出Python官网发布的会议时间、名称和地点。

    # !/usr/bin/env/Python3 # - * - coding: utf-8 - * - from html.parser import HTMLParser import urllib ...

  3. python 基础 7.1 datetime 获得时间

    一 datatime 的使用   object         timedeta         tzinfo         time         data                dat ...

  4. Python中Tk模块简单窗口设计

    Python中Tk和PyQt都可以设计小程序,区别在于:Tk界面美观度相对较差,但由于是Python的内置模块,最终生成的程序大小相比于PyQt较小. import tkinter # 导入TKint ...

  5. python笔记7:日期和时间

    Python 提供了一个 time 和 calendar 模块可以用于格式化日期和时间. 时间间隔是以秒为单位的浮点小数. 每个时间戳都以自从1970年1月1日午夜(历元)经过了多长时间来表示. 时间 ...

  6. python有超时的windows系统时间设置代码

    手边的笔记本用久了,cmos电池可能又没电了.每次开机时间都不对,导致访问一些有https的网页会出现警告信息. 于是找了找通过python脚本设置系统时间的方法,发现了两种,其一是调用socket直 ...

  7. Python中为feedparser设置超时时间教程

    python有一个用于解析feed的模块:feedparser,feedparser解析各种feed是非常方便的,唯一比较恼火的是遇到一些badurl,经常会导致堵塞,因此需要为feedparser设 ...

  8. python datetime模块用strftime 格式化时间

    1 2 3 #!usr/bin/python import datetime datetime.datetime.now() 这个会返回 microsecond.因此这个是我们不需要的.所以得做一下修 ...

  9. Python中用datetime包进行对时间的一些操作

    1. 计算给出两个时间之间的时间差 import datetime as dt # current time cur_time = dt.datetime.today() # one day pre_ ...

随机推荐

  1. JDBC批处理---(java 对数据库的回滚) .

    1先看一下程序: package com.redking.jdbc.demo;    import java.sql.Connection;    import java.sql.DriverMana ...

  2. 在Ubuntu下安装imx6linux系统的交叉编译环境遇到的问题总结

    这段时间一直忙于手上的嵌入式项目,可以说自己从嵌入式的菜鸟一点点的入门了,关于嵌入式和imx6核心板的开发有了一点的了解,尤其是对于板子环境的搭建.硬件的开发,搭建环境,是一个很大的工程量,也是很重要 ...

  3. Redis安装教程

    1. Linux下Redis安装教程 (1)安装 #tar xf redis-2.6.14.tar.gz #cd redis-2.6.14 #make #make install (2)配置 修改re ...

  4. POJ 1753 Flip Game (高斯消元 枚举自由变元求最小步数)

    题目链接 题意:4*4的黑白棋,求把棋全变白或者全变黑的最小步数. 分析:以前用状态压缩做过. 和上题差不多,唯一的不同是这个终态是黑棋或者白棋, 但是只需要把给的初态做不同的两次处理就行了. 感觉现 ...

  5. HNOI2002营业额统计(平衡树)

    标准的平衡树. 贴个splay吧 var v,l,r,fa:..] of longint; root,x,i,n,ans:longint; procedure zig(x:longint); var ...

  6. android Log图文详解(Log.v,Log.d,Log.i,Log.w,Log.e)

    在Android群里,经常会有人问我,Android Log是怎么用的,今天我就把从网上以及SDK里东拼西凑过来,让大家先一睹为快,希望对大家入门Android Log有一定的帮助. android. ...

  7. hdu 4617 Weapon(叉积)

    大一学弟表示刚学过高数,轻松无压力. 我等学长情何以堪= = 求空间无限延伸的两个圆柱体是否相交,其实就是叉积搞一搞 详细点就是求两圆心的向量在两直线(圆心所在的直线)叉积上的投影 代码略挫,看他的吧 ...

  8. BZOJ 1861 书架

    (╯-_-)╯╧╧ 此处为错误代码. #include<iostream> #include<cstdio> #include<cstring> #include& ...

  9. angular js 实例参数学习

    <!DOCTYPE html> <html> <head> <meta name="description" content=" ...

  10. Mac下开发常用目录

    1:Snippets    Xcode 代码段的文件表示 ~/Library/Developer/Xcode/UserData/CodeSnippets/ 2: Services  可以添加workf ...