網站首頁 編程語言 正文
之前搗鼓樹莓派時,要求做一個番茄鐘,但最后就只是搞成一個與樹莓派沒啥關系的py程序,雖然簡陋,但就此記錄一下自學的成果。
程序實現番茄工作法:25分鐘工作,5分鐘休息
完成一次番茄工作時間,就記一個番茄
(不把休息時間算在里面,有時候自己都不想休息,好吧,是我不知道怎么把番茄工作時間和休息時間聯系在一塊來記錄番茄個數)
這個程序倒計時顯示的是從24:59開始,是因為按的時候算是1秒?
運行界面如下:
自己感覺這個界面還行,樸素中帶著點高級感
代碼參考了一些大佬寫的番茄鐘程序,特別是那個倒計時的實現,很神奇.
代碼如下:
import tkinter
from tkinter import messagebox
import time
#創建番茄鐘窗口
root = tkinter.Tk()
root.title('番茄鐘小程序')
root.geometry('300x300')
root.configure(bg='Tomato')
#創建計數的
count = 0
#創建完成計時后的彈窗
def mymsg():
tkinter.messagebox.showinfo("提示", "恭喜完成一個番茄鐘!!記得休息一下")
def mymsg2():
tkinter.messagebox.showinfo("提示", "休息完畢!")
#創建番茄計時函數
# strptime()函數將字符串轉換為datetime
def tomato_clock():
remain_time = 1500
bb = time.strftime('/ %M:%S', time.gmtime(remain_time))
lb2.configure(text=bb)
lb3.configure(text='剩余時間/總時間')
for i in range(1500):
remain_time -= 1
aa = time.strftime('%M:%S', time.gmtime(remain_time))
lb.configure(text=aa)
root.update()
time.sleep(1)
if remain_time == 0:
tomato_count()
mymsg()
#創建計數的函數
def tomato_count():
global count
count += 1
lb4.configure(text=count)
#創建休息時間函數
def relax():
remain_time = 300
bbb = time.strftime('/ %M:%S', time.gmtime(remain_time))
lb2.configure(text=bbb)
lb3.configure(text='剩余時間/總時間')
for i in range(300):
remain_time -= 1
aaa = time.strftime('%M:%S', time.gmtime(remain_time))
lb.configure(text=aaa)
root.update()
time.sleep(1)
if remain_time == 0:
mymsg2()
#創建各種標簽
#番茄動態計時
lb = tkinter.Label(root, text=' ', bg='Tomato', fg='white', font='Verdana 16 bold', width=7, height=1)
lb.place(x=50, y=100)
#番茄固定時間
lb2 = tkinter.Label(root, text=' ', bg='Tomato', fg='white', font='Verdana 16 bold', width=8, height=1)
lb2.place(x=138, y=100)
#剩余時間/總時間
lb3 = tkinter.Label(root, text=' ', bg='Tomato', fg='white', font='Verdana 16 bold', width=14, height=2)
lb3.place(x=50, y=44)
#番茄個數顯示
lb4 = tkinter.Label(root, text='0', bg='Tomato', fg='white', font='Verdana 16 bold', width=7, height=1)
lb4.place(x=25, y=20)
#左上角的 番茄:
lb5 = tkinter.Label(root, text='番茄:', bg='Tomato', fg='white', font='Verdana 16 bold', width=4, height=1)
lb5.place(x=5, y=20)
#按鈕
#開啟一個番茄
Button1 = tkinter.Button(root, text='開啟一個番茄', bg='orange', fg='black', font='Verdana 13 bold', width=15, height=1, command=tomato_clock)
Button1.place(x=70, y=150)
#休息一下
Button2 = tkinter.Button(root, text='休息一下', bg='cornflowerblue', fg='black', font='Verdana 13 bold', width=15, height=1, command=relax)
Button2.place(x=70, y=200)
#循環
root.mainloop()
原文鏈接:https://blog.csdn.net/X_chaotu/article/details/127328735
相關推薦
- 2023-04-01 Python使用pptx實現復制頁面到其他PPT中_python
- 2022-11-14 python流程控制語句
- 2022-06-27 ASP.net?Core微信平臺開發配置Token_實用技巧
- 2022-11-30 ASP.NET?MVC實現本地化和全球化_實用技巧
- 2022-11-15 如何將Android?Studio卸載干凈_Android
- 2023-01-15 使用tf.keras.MaxPooling1D出現錯誤問題及解決_python
- 2022-07-21 centos docker容器優化清理磁盤空間以及內存占用
- 2022-05-04 C#異步編程由淺入深(三)之詳解Awaiter_C#教程
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支