#coding=utf-8
import os
from datetime import datetime
import psutil
import sys
from time import sleep
from Tkinter import *
import tkMessageBox
import time
def tick():
global time1
# 获取当前系统时间
time2 = time.strftime('%H:%M:%S')
# 动态显示
if time2 != time1:
time1 = time2
clock.config(text=time2)
clock.after(200, tick)
def timer():
global dTime1
bTime = datetime.fromtimestamp(psutil.boot_time())
cTime = datetime.now()
dTime2 = (cTime - bTime).seconds
if dTime2 != dTime1:
dTime1 = dTime2
runn.config(text=str(dTime2)+' s')
runn.after(800, timer)
def msg():
global count
if (dTime1/7200 > count):
tkMessageBox.showinfo(title = 'Notice', message = 'You Should Have a Rest Now')
count+=1
tips.config(text="累计提示次数:"+str(count))
tips.after(800, msg)
root = Tk()
#标题栏
root.title('Tik')
#窗体尺寸
#root.geometry('200x100')
#时钟
nclock = Label(root, text="当前时间", font=('DengXian', 15, 'bold'), relief=GROOVE)
nclock.grid(row=0, column=0)
time1 = ''
clock = Label(root, font=('DengXian', 15, 'bold'))
clock.grid(row=0, column=1)
tick()
#开机时间
nboot = Label(root, text="开机时间", font=('DengXian', 15, 'bold'), relief=GROOVE)
nboot.grid(row=1, column=0)
boottime = datetime.fromtimestamp(psutil.boot_time())
boottime = boottime.strftime('%H:%M:%S')
boot = Label(root, text=boottime, font=('DengXian', 15, 'bold'))
boot.grid(row=1, column=1)
#运行时长
nrun = Label(root, text="运行时长", font=('DengXian', 15, 'bold'), relief=GROOVE)
nrun.grid(row=2, column=0)
dTime1 = ''
runn = Label(root, font=('DengXian', 15, 'bold'))
runn.grid(row=2, column=1)
timer()
#运行状态
status = Label(root, text=" [ Running ] ", fg = 'green', bg = 'black', font=('DengXian', 10, 'bold'))
status.grid(row=10, column=0)
count = 0
tips = Label(root, fg = 'green', bg = 'black', font=('DengXian', 10, 'bold'))
tips.grid(row=10, column=1)
msg()
root.mainloop()