From dc82a65a2e7b06d558cde340d8fd625a62eff3e1 Mon Sep 17 00:00:00 2001 From: William533036 <69657041@qq.com> Date: Fri, 17 Jan 2020 23:11:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=BA=E5=8F=AF=E9=9A=8F?= =?UTF-8?q?=E6=97=B6=E4=BF=AE=E6=94=B9=EF=BC=8C=E5=A2=9E=E5=8A=A0=E9=BB=98?= =?UTF-8?q?=E8=AE=A430=E5=88=86=E9=92=9F=E7=9A=84=E7=82=B9=E5=87=BB?= =?UTF-8?q?=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CareForCoders.py" | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git "a/53.Python\345\270\256\345\212\251\344\270\207\345\215\203\347\250\213\345\272\217\345\221\230\350\277\234\347\246\273\347\214\235\346\255\273/CareForCoders.py" "b/53.Python\345\270\256\345\212\251\344\270\207\345\215\203\347\250\213\345\272\217\345\221\230\350\277\234\347\246\273\347\214\235\346\255\273/CareForCoders.py" index a4a3773..9b9ab56 100644 --- "a/53.Python\345\270\256\345\212\251\344\270\207\345\215\203\347\250\213\345\272\217\345\221\230\350\277\234\347\246\273\347\214\235\346\255\273/CareForCoders.py" +++ "b/53.Python\345\270\256\345\212\251\344\270\207\345\215\203\347\250\213\345\272\217\345\221\230\350\277\234\347\246\273\347\214\235\346\255\273/CareForCoders.py" @@ -9,6 +9,7 @@ # @File : CareForCoders.py from tkinter import * + from tkinter.messagebox import showwarning, showinfo import time from ctypes import * @@ -33,6 +34,7 @@ def close_windows(): class CareForCoders: def __init__(self): self.countdown_lb = None + self.default_minutes = 30 def user_setting(self): note = LabelFrame(root, text="说明", padx=10, pady=10, @@ -51,19 +53,23 @@ def user_setting(self): self.countdown_lb = Label(text="休息倒计时:", justify=LEFT, font=("黑体", '11')) self.countdown_lb.grid(row=2) + self.submit = Button(root, text="启动", width=8, - command=lambda: self.get_countdown(self.time_entry.get()) + command=lambda: self.get_countdown(self.time_entry.get() if self.time_entry.get() else 30) ) + self.submit.grid(row=3, column=0, pady=10) - def get_countdown(self, countdown): + + def get_countdown(self, countdown=30): + self.default_minutes = countdown try: _float_countdown = float(countdown) if _float_countdown <= 0: showwarning("提示:", message="倒计时必须为正数!") else: - self.time_entry.config(state=DISABLED) - self.submit.config(state=DISABLED) + self.time_entry.config(state=NORMAL) + self.submit.config(state=NORMAL) self.countdown_show(_float_countdown * 60) except ValueError: showwarning("提示:", message="请填写正确的倒计时!") @@ -82,10 +88,9 @@ def countdown_show(self, countdown_sec): if countdown_sec < 1: # 启动锁屏操作 close_windows() - time.sleep(3) self.countdown_lb.config(text="欢迎主人回来...") - self.time_entry.config(state=NORMAL) - self.submit.config(state=NORMAL) + time.sleep(3) + self.get_countdown(self.default_minutes) return @staticmethod @@ -93,7 +98,7 @@ def notice(): message = Toplevel(root) message.wm_attributes('-topmost', 1) center_window(message, 400, 200) - Label(message, text='主人,辛苦工作这么久了,准备休息下吧!' + Label(message, text='黄英杰,辛苦工作这么久了,准备休息下吧!' , justify=CENTER, fg='red', font=("黑体", '15')).grid() time.sleep(5) message.destroy() @@ -101,9 +106,9 @@ def notice(): if __name__ == '__main__': root = Tk() - center_window(root, 260, 200) + center_window(root, 300, 250) root.resizable(width=False, height=False) - root.title('久坐提醒 by:清风Python') + root.title('久坐提醒 修改by:黄英杰') Main = CareForCoders() Main.user_setting() root.mainloop()