0% found this document useful (0 votes)
13 views2 pages

Import Tkinter As TK

This document contains a Python script that creates a countdown timer using the Tkinter library. Users can input a time in minutes, and the timer counts down, updating every second until it reaches zero. The interface includes labels for instructions, the timer display, and a background label with the author's name.

Uploaded by

mzomafaith
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views2 pages

Import Tkinter As TK

This document contains a Python script that creates a countdown timer using the Tkinter library. Users can input a time in minutes, and the timer counts down, updating every second until it reaches zero. The interface includes labels for instructions, the timer display, and a background label with the author's name.

Uploaded by

mzomafaith
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

import tkinter as tk

import time

def start_timer():

try:

# Get the time input from the user (in minutes)

minutes = int(entry.get())

seconds = minutes * 60

except ValueError:

label_result.config(text=”Please enter a valid number!”)

return

countdown(seconds)

def countdown(seconds):

if seconds >= 0:

mins, secs = divmod(seconds, 60)

timer = ‘{:02d}:{:02d}’.format(mins, secs)

label_timer.config(text=timer)

window.after(1000, countdown, seconds - 1) # Update every second

else:

label_timer.config(text=”Time’s up!”)

# Create the main window

window = tk.Tk()

window.title(”Countdown Timer”)
# Create and place the widgets

label_instruction = tk.Label(window, text=”Enter minutes:”)

label_instruction.pack()

entry = tk.Entry(window)

entry.pack()

start_button = tk.Button(window, text=”Start Timer”, command=start_timer)

start_button.pack()

label_timer = tk.Label(window, text=”00:00”, font=(”Helvetica”, 48))

label_timer.pack()

label_result = tk.Label(window, text=””, font=(”Helvetica”, 12))

label_result.pack()

# Add your name as a background label

label_name_background = tk.Label(window, text=”By Favour Joshua Mzoma”, font=(”Helvetica”,


10), fg=”lightgrey”)

label_name_background.place(relx=0.5, rely=1.0, anchor=”center”)

# Start the Tkinter event loop

window.mainloop()

You might also like