網(wǎng)站首頁 編程語言 正文
之前搗鼓樹莓派時,要求做一個番茄鐘,但最后就只是搞成一個與樹莓派沒啥關(guān)系的py程序,雖然簡陋,但就此記錄一下自學的成果。
程序?qū)崿F(xiàn)番茄工作法:25分鐘工作,5分鐘休息
完成一次番茄工作時間,就記一個番茄
(不把休息時間算在里面,有時候自己都不想休息,好吧,是我不知道怎么把番茄工作時間和休息時間聯(lián)系在一塊來記錄番茄個數(shù))
這個程序倒計時顯示的是從24:59開始,是因為按的時候算是1秒?
運行界面如下:
自己感覺這個界面還行,樸素中帶著點高級感
代碼參考了一些大佬寫的番茄鐘程序,特別是那個倒計時的實現(xiàn),很神奇.
代碼如下:
import tkinter
from tkinter import messagebox
import time
#創(chuàng)建番茄鐘窗口
root = tkinter.Tk()
root.title('番茄鐘小程序')
root.geometry('300x300')
root.configure(bg='Tomato')
#創(chuàng)建計數(shù)的
count = 0
#創(chuàng)建完成計時后的彈窗
def mymsg():
tkinter.messagebox.showinfo("提示", "恭喜完成一個番茄鐘??!記得休息一下")
def mymsg2():
tkinter.messagebox.showinfo("提示", "休息完畢!")
#創(chuàng)建番茄計時函數(shù)
# strptime()函數(shù)將字符串轉(zhuǎn)換為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()
#創(chuàng)建計數(shù)的函數(shù)
def tomato_count():
global count
count += 1
lb4.configure(text=count)
#創(chuàng)建休息時間函數(shù)
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()
#創(chuàng)建各種標簽
#番茄動態(tài)計時
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)
#番茄個數(shù)顯示
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)
#循環(huán)
root.mainloop()
原文鏈接:https://blog.csdn.net/X_chaotu/article/details/127328735
相關(guān)推薦
- 2022-07-16 構(gòu)建npm配置包
- 2022-07-01 Go?函數(shù)中獲取調(diào)用者的函數(shù)名和文件名及行號_Golang
- 2022-04-09 Eclipse 中Deployment Assembly 無法正常顯示
- 2022-06-14 Docker?配置容器固定IP的方法_docker
- 2023-07-29 highcharts中g(shù)antt甘特圖的使用
- 2023-10-26 video標簽未自動播放,autoplay無效,video不能自動播放的原因分析
- 2022-03-23 詳細聊聊Redis的過期策略_Redis
- 2022-06-30 C語言詳細圖解浮點型數(shù)據(jù)的存儲實現(xiàn)_C 語言
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細win安裝深度學習環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支