SoFunction
Updated on 2024-11-15

Python use tkinter to achieve a simple tomato clock sample code

Before tinkering with the Raspberry Pi, asked to make a tomato clock, but in the end just get into a py program that has nothing to do with the Raspberry Pi, although simple, but this record of the results of self-study.

Program implementation of the tomato work method: 25 minutes of work, 5 minutes of rest

Complete a tomato work time, mark a tomato

(Not counting breaks, sometimes I don't even want to take a break myself, well, I don't know how to link tomato work time to break time to keep track of the number of tomatoes)

This program's countdown shows that it starts at 24:59 because it's considered 1 second when pressed?

The runtime interface is as follows:

I feel that the interface is okay, plain with a little bit of high quality

The code references some of the tomato clock programs written by the big boys, especially the implementation of the countdown timer, it's amazing.

The code is as follows:

import tkinter
from tkinter import messagebox
import time
 
# Create a Tomato Clock window
root = ()
('Tomato clock applet')
('300x300')
(bg='Tomato')
 
#Creating counts of
count = 0
 
#create a pop-up window after the completion of the timer
def mymsg():
    ("Tip.", "Congratulations on completing a tomato clock! Remember to take a break.")
def mymsg2():
    ("Tip.", "Rest is over!")
 
 
# Create a tomato timer function
# strptime() function converts strings to datetime
def tomato_clock():
    remain_time = 1500
    bb = ('/  %M:%S', (remain_time))
    (text=bb)
    (text='Remaining time/total time')
    for i in range(1500):
        remain_time -= 1
        aa = ('%M:%S', (remain_time))
        (text=aa)
        ()
        (1)
        if remain_time == 0:
            tomato_count()
            mymsg()
 
# Functions that create counts
def tomato_count():
    global count
    count += 1
    (text=count)
 
#Creating a rest time function
def relax():
    remain_time = 300
    bbb = ('/  %M:%S', (remain_time))
    (text=bbb)
    (text='Remaining time/total time')
    for i in range(300):
        remain_time -= 1
        aaa = ('%M:%S', (remain_time))
        (text=aaa)
        ()
        (1)
        if remain_time == 0:
            mymsg2()
 
#Creating Various Labels
 
#Tomato Dynamic Timing
lb = (root, text=' ', bg='Tomato', fg='white', font='Verdana 16 bold', width=7, height=1)
(x=50, y=100)
 
#Tomato Fixed Time
lb2 = (root, text=' ', bg='Tomato', fg='white', font='Verdana 16 bold', width=8, height=1)
(x=138, y=100)
 
# of time remaining/total time
lb3 = (root, text=' ', bg='Tomato', fg='white', font='Verdana 16 bold', width=14, height=2)
(x=50, y=44)
 
# of tomatoes displayed
lb4 = (root, text='0', bg='Tomato', fg='white', font='Verdana 16 bold', width=7, height=1)
(x=25, y=20)
 
# Top left corner of the tomato:
lb5 = (root, text='Tomatoes:', bg='Tomato', fg='white', font='Verdana 16 bold', width=4, height=1)
(x=5, y=20)
 
 
#buttons
#Turn on a tomato
Button1 = (root, text='Turn on a tomato', bg='orange', fg='black', font='Verdana 13 bold', width=15, height=1, command=tomato_clock)
(x=70, y=150)
 
# Take a break
Button2 = (root, text='Take a break', bg='cornflowerblue', fg='black', font='Verdana 13 bold', width=15, height=1, command=relax)
(x=70, y=200)
 
#Cycle
()

to this article on the use of Python tkinter to achieve a simple tomato clock sample code is introduced to this article, more related Python tkinter tomato clock content, please search for my previous posts or continue to browse the following related articles I hope you will support me in the future more!