参考资料:

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. brew命令

    下面参考下网友的总结: 查看brew的帮助 brew –help 安装软件 brew install git 卸载软件 brew uninstall git 搜索软件 brew search git ...

  2. 261. Graph Valid Tree

    题目: Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nod ...

  3. 遍历并remove HashMap中的元素时,遇到ConcurrentModificationException

    遍历并remove HashMap中的元素时,遇到ConcurrentModificationException for (Map.Entry<ImageView, UserConcise> ...

  4. WIN32编程杂记(一)

    1.UNREFERENCED_PARAMETER的用处 作用:告诉编译器,已经使用了该变量,不必检测警告! 在VC编译器下,如果您用最高级别进行编译,编译器就会很苛刻地指出您的非常细小的警告.当你生命 ...

  5. hadoop2 环境的搭建(自动HA)

    zookeeper:hadoop112.hadoop113.hadoop114 namenode:hadoop110和hadoop111 datanode:hadoop112.hadoop113.ha ...

  6. HDU 4923

    题目大意: 给出一串序列Ai{0,1},求一个序列Bi[0,1](Bi<Bi+1),使得sigama(Ai-Bi)^2最小 思路: 若B相同,则取A的平均数可使方差最小 若B有序,   若A== ...

  7. asp.net清除页面缓存防止同时登录

    //清除页面缓存,防止页面回退重复提交数据 在页面里做以下设置就可以使页面的缓存失效,每次都需要获取新页面. Response.Cache.SetCacheability(System.Web.Htt ...

  8. Codeforces Round #271 (Div. 2)

    A. Keyboard 题意:一个人打字,可能会左偏一位,可能会右偏一位,给出一串字符,求它本来的串 和紫书的破损的键盘一样 #include<iostream> #include< ...

  9. 手动配置gradle

    最近从github倒入项目,运行的特别慢gradle配置有问题,解决方法: 1.C:\android\demo\hellocharts-android-master\gradle\wrapper 目录 ...

  10. 页面多个Jquery版本共存的冲突问题,解决方法!

    示例如下: <script type="text/javascript" src="jquery.js"></script> <s ...