Python Final MP
Python Final MP
Submitted By
Guided By
Miss. Gurav.J.N
Date – / /
Place – Talsande
INDEX
1 Introduction 1
2 2
Class in Python
3 3
Object of Python
4 4-6
Source Code
5 7-8
Output
6 9
Conclusion
7 10
References
Create Simple Alarm Clock Using Class And Object
Introduction
The simple alarm clock project aims to create a Python application that allows users
to set an alarm for a specific time. When the alarm time is reached, the program will
notify the user, potentially through a simple text message or a sound, depending on
the project's scope. This project is structured around the creation of an AlarmClock
class, which encapsulates all functionalities related to the alarm clock, such as setting
the alarm, checking the current time against the alarm time, and triggering the alarm.
Objectives
Introduce Basic OOP Concepts: Use classes and objects to model an alarm clock,
introducing the student to encapsulation and instance methods.
Work with Time: Utilize Python's time module to retrieve the current time, set
alarm times, and compare times to determine when the alarm should go off.
Event Handling: Implement a basic form of event handling by checking at regular
intervals if the current time matches the set alarm time, and if so, trigger an action.
Key Features
Set Alarm: Allow the user to input a specific time for the alarm to go off.
Alarm Notification: When the current time matches the set alarm time, notify the
user through a printed message or a sound.
Continuous Time Check: Implement a loop that continuously checks the current
time against the set alarm time and triggers the alarm at the correct moment.
Implementation Steps
Define the AlarmClock Class: This class contains methods for setting the alarm
time, checking the current time, and triggering the alarm.
Use the Time Module: Import Python's built-in time module to work with times,
including fetching the current time and formatting times for comparison.
Main Loop: Implement a main loop that runs indefinitely, checking if the current
time matches the alarm time and triggering the alarm if necessary.
Class in Python
A class is a user-defined blueprint or prototype from which objects are created.
Classes provide a means of bundling data and functionality together. Creating a new
class creates a new type of object, allowing new instances of that type to be made.
Each class instance can have attributes attached to it for maintaining its state. Class
instances can also have methods (defined by their class) for modifying their state.
To understand the need for creating a class and object in Python let’s consider an
example, let’s say you wanted to track the number of dogs that may have different
attributes like breed and age. If a list is used, the first element could be the dog’s
breed while the second element could represent its age. Let’s suppose there are 100
different dogs, then how would you know which element is supposed to be which?
What if you wanted to add other properties to these dogs? This lacks organization
and it’s the exact need for classes.
class ClassName:
# Statement
obj = ClassName()
print(obj.atrr)
The class creates a user-defined data structure, which holds its own data members
and member functions, which can be accessed and used by creating an instance of
that class. A class is like a blueprint for an object.
Object of Python
Syntax:
obj = MyClass()
print(obj.x)
Instance defining represent memory allocation necessary for storing the actual data
of variables. Each time when you create an object of class a copy of each data
variable defined in that class is created. In simple language, we can state that each
object of a class has its own copy of data members defined in that class.
Source Code
# Import Required Library
from tkinter import *
import datetime
import time
import winsound
from threading import *
# Create Object
root = Tk()
# Set geometry
root.geometry("400x200")
# Use Threading
def Threading():
t1=Thread(target=alarm)
t1.start()
def alarm():
# Infinite Loop
while True:
# Set Alarm
set_alarm_time = f"{hour.get()}:{minute.get()}:{second.get()}"
frame = Frame(root)
frame.pack()
hour = StringVar(root)
hours = ('00', '01', '02', '03', '04', '05', '06', '07',
'08', '09', '10', '11', '12', '13', '14', '15',
'16', '17', '18', '19', '20', '21', '22', '23', '24'
)
hour.set(hours[0])
second = StringVar(root)
seconds = ('00', '01', '02', '03', '04', '05', '06', '07',
'08', '09', '10', '11', '12', '13', '14', '15',
'16', '17', '18', '19', '20', '21', '22', '23',
'24', '25', '26', '27', '28', '29', '30', '31',
'32', '33', '34', '35', '36', '37', '38', '39',
'40', '41', '42', '43', '44', '45', '46', '47',
'48', '49', '50', '51', '52', '53', '54', '55',
'56', '57', '58', '59', '60')
second.set(seconds[0])
Button(root,text="SetAlarm",font=("Helvetica
15"),command=Threading).pack(pady=20)
# Execute Tkinter
root.mainloop()
Output
Conclusion
This simple alarm clock project not only reinforces fundamental programming
concepts but also opens avenues for exploring more complex programming paradigms
and libraries in Python. As learners progress, they can incrementally add features,
refactor the codebase for efficiency and readability, and perhaps most importantly,
think critically about how to model and solve problems programmatically. Whether as
a stepping stone to more advanced projects or a practice exercise in Python basics, the
simple alarm clock serves as a practical and educational tool in any developer's
journey.
References
https://chat.openai.com/c/e565941e-cddc-411e-b805-
https://www.javatpoint.com/python-objects-classes
https://www.geeksforgeeks.org/creat-an-alarm-clock-using-tkinter/
https://www.codingnepalweb.com/simple-alarm-clock-html-javascript/