Python做的眼睛护士

搞了两天终于搞定了,虽然还存在一点点小问题(窗口的显示位置应该设在(0,0))。但基本可以用了。

代码分两个部分。主界面和遮挡屏幕界面。主界面设置完时间后调用遮挡屏幕界面。

1.主界面(设置 工作时间 和 休息时间(单位为:秒))

#-*-coding:utf-8-*-
import Tkinter,time,tkMessageBox,sys,BeBigModule
class MainFrame:
    def __init__(self):
        self.frame=Tkinter.Frame()
        self.frame.pack()
        
        contentsWork=Tkinter.StringVar()
        contentsRelax=Tkinter.StringVar()
        
        self.entryWorkWidget=Tkinter.Entry(self.frame,text=contentsWork)
        contentsWork.set('input workTime here:')
        self.entryWorkWidget["width"]=35                 #这句话和下句话的先后顺序不会影响程序
        self.entryWorkWidget.pack(side='top')
        
        self.entryRelaxWidget=Tkinter.Entry(self.frame,text=contentsRelax)
        contentsRelax.set('input relaxTime here:')
        self.entryRelaxWidget.config(width=35)
        self.entryRelaxWidget.pack(side='top')
        
        self.startButton=Tkinter.Button(self.frame,text="OK",command=self.start)
        self.startButton.pack(side='left')
        
        self.quitButton=Tkinter.Button(self.frame,text="Exit",command=self.quit)
        self.quitButton.pack(side='right')
        self.frame.mainloop()
    def start(self):
        workTime=self.entryWorkWidget.get().strip()
        workTimeNum=int(workTime)   
#         self.frame.deiconify()
#         self.frame.withdraw     
        relaxTime=self.entryRelaxWidget.get().strip()
        relaxTimeNum=int(relaxTime)
        
        self.frame.destroy()
        beBigFrame=BeBigModule.BeBig(workTimeNum,relaxTimeNum)
       
    def quit(self):
        pass
# root=Tkinter.Tk()
# root.title("CountDowm")
# 
# mainFrame=MainFrame(root)
# root.mainloop()
mainFrame=MainFrame()
#目前来看就剩个问题了,怎么设定窗口的显示位置

2.遮挡屏幕界面

import Tkinter,sys,time
class BeBig():
    workTime=0
    relaxTime=0
    root=Tkinter.Tk()
    Label1=Tkinter.Label(root,text=time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())))
    def __init__(self,workTimeNum,relaxTimeNum):
        self.workTime=workTimeNum
        self.relaxTime=relaxTimeNum    
        self.root.minsize(self.root.winfo_screenwidth(), self.root.winfo_screenheight())
        #self.root.geometry('300x200-100-100')
        self.root.config(bg='black')
        
        self.Label1.pack(side='top')
        topTitle=self.root.winfo_toplevel()
        topTitle.overrideredirect(True)
        self.trickit(self.relaxTime,self.workTime)
        self.root.mainloop()
    def trickit(self,relaxTime,workTime):
        for j in range(relaxTime,0,-1):
            self.Label1["text"]=j
            self.root.update()
            time.sleep(1)
            
        self.root.withdraw()
        time.sleep(workTime)
        self.root.minsize(self.root.winfo_screenwidth(), self.root.winfo_screenheight())
        self.root.update()
        self.root.deiconify()
        self.trickit(self.relaxTime,self.workTime)
# beBig.beBig()

相关推荐