参考资料:

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. 258. Add Digits

    题目: Given a non-negative integer num, repeatedly add all its digits until the result has only one di ...

  2. Miller-Rabin素数测试学习小计

    1.Miller-Rabin是干啥的?它是用来检测一个数字(一般是很大的数字)是不是素数: 2.Miller-Rabin算法基于的两个定理: (1)费尔马小定理:如果p是一个素数,且0<a< ...

  3. TeeChart的X轴为时间,多个Y轴的显示

    最后上代码 public partial class Test : Form { private TChart tChart = new TChart(); ; public Test() { Ini ...

  4. Error running app: Instant Run requires 'Tools | Android | Enable ADB integration' to be enabled.解决办法

    刚刚更新AS到2.0版本,然后导入Api Demos的时候出现了这个错误. 解决办法:在AS的菜单栏,Tools->Android ->Enable ADB integration 勾选就 ...

  5. [51NOD]BSG白山极客挑战赛

    比赛链接:http://www.51nod.com/contest/problemList.html#!contestId=21 /* ━━━━━┒ギリギリ♂ eye! ┓┏┓┏┓┃キリキリ♂ min ...

  6. hdu 4973 A simple simulation problem. (线段树)

    题目链接 题意: 给定n长的序列 m个操作 序列默认为 1, 2, 3···n 操作1:D [l,r] 把[l,r]区间增长 :( 1,2,3,4 进行 D [1,3]变成 1,1,2,2,3,3,4 ...

  7. jquery 滚动条插件 jquery.nanoscroller.js

    $(".listcontent .nano").nanoScroller();   $(".chatcontent .nano").nanoScroller({ ...

  8. php linux部署相关

    http://www.itbulu.com/wdcp-php55.html http://www.wdlinux.cn/wdcp/install.html http://www.yiichina.co ...

  9. I.MX6 Ethernet UI patch failed

    /*********************************************************************** * I.MX6 Ethernet UI patch f ...

  10. HDU 5289 Assignment (数字序列,ST算法)

    题意: 给一个整数序列,多达10万个,问:有多少个区间满足“区间最大元素与最小元素之差不超过k”.k是给定的. 思路: 如果穷举,有O(n*n)复杂度.可以用ST算法先预处理每个区间最大和最小,O(n ...