Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
4 views

Python Final MP

Uploaded by

mandarlolage51
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Python Final MP

Uploaded by

mandarlolage51
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

D.Y.

PATIL TECHNICAL CAMPUS, TALSANDE


FACULTY OF ENGINEERING & FACULTY OF
MANAGEMENT
(Polytechnic)

A Micro project Report On


“Create Simple Alarm Clock Using Class And Object ”

Submitted By

Enrollment No. Name

2112200034 Sanika Sagar Yadav

Guided By
Miss. Gurav.J.N

D.Y.PATIL TECHNICAL CAMPUS, TALSANDE FACULTY OF


ENGINEERING & FACULTY OF MANAGEMENT
(Polytechnic)

DEPARTMENT OF COMPUTER ENGINEERING


SEMESTER VI
CERTIFICATE

This is Certify that student of Computer Engineering has successfully


completed the project term work “Create Simple Alarm Clock Using Class
And Object ” in partial fulfillment of the Diploma of Engineering in Computer
as laid down during academic year 2023-24.

Roll No. Name of Student Exam Seat No.


3209 Sanika Sagar Yadav

Miss. Gurav. J. N Mr. Kumbhar R. S.


Project Guide HoD

Dr. S.R. Pawaskar


Principal

Date – / /
Place – Talsande
INDEX

Sr No. Title Page No.

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.

D. Y. Patil Technical Campus Faculty Of Engineering & Faculty Of Management,


Talsande (Polytechnic)
Create Simple Alarm Clock Using Class And Object

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.

Syntax: Class Definition

class ClassName:

# Statement

Syntax: Object Definition

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.

Some points on Python class:

 Classes are created by keyword class.


 Attributes are the variables that belong to a class.
 Attributes are always public and can be accessed using the dot (.) operator.
Eg.: My class.Myattribute

D. Y. Patil Technical Campus Faculty Of Engineering & Faculty Of Management,


Talsande (Polytechnic)
Create Simple Alarm Clock Using Class And Object

Object of Python

An Object is an instance of a Class. A class is like a blueprint while an instance is a


copy of the class with actual values. Python is an object-oriented programming
language that stresses objects i.e. it mainly emphasizes functions. Python Objects
are basically an encapsulation of data variables and methods acting on that data into
a single entity.

 Understanding of Python Object


For a better understanding of the concept of objects in Python. Let’s consider an
example, many of you have played CLASH OF CLANS, So let’s assume base
layout as the class which contains all the buildings, defenses, resources, etc. Based
on these descriptions we make a village, here the village is the object in 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.

Creating a Python Object


Working of the Program: Audi = Cars()

 A block of memory is allocated on the heap. The size of memory allocated is


decided by the attributes and methods available in that class(Cars).
 After the memory block is allocated, the special method __init__() is called
internally. Initial data is stored in the variables through this method.
 The location of the allocated memory address of the instance is returned to
the object(Cars).
 The memory location is passed to self.

D. Y. Patil Technical Campus Faculty Of Engineering & Faculty Of Management,


Talsande (Polytechnic)
Create Simple Alarm Clock Using Class And Object

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()}"

# Wait for one seconds


time.sleep(1)

# Get current time


current_time = datetime.datetime.now().strftime("%H:%M:%S")
print(current_time,set_alarm_time)

D. Y. Patil Technical Campus Faculty Of Engineering & Faculty Of Management,


Talsande (Polytechnic)
Create Simple Alarm Clock Using Class And Object

# Check whether set alarm is equal to current time or not


if current_time == set_alarm_time:
print("Time to Wake up")
# Playing sound
winsound.PlaySound("sound.wav",winsound.SND_ASYNC)

# Add Labels, Frame, Button, Optionmenus


Label(root,text="Alarm Clock",font=("Helvetica 20 bold"),fg="red").pack(pady=10)
Label(root,text="Set Time",font=("Helvetica 15 bold")).pack()

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])

hrs = OptionMenu(frame, hour, *hours)


hrs.pack(side=LEFT)
minute = StringVar(root)
minutes = ('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')
minute.set(minutes[0])

D. Y. Patil Technical Campus Faculty Of Engineering & Faculty Of Management,


Talsande (Polytechnic)
Create Simple Alarm Clock Using Class And Object

mins = OptionMenu(frame, minute, *minutes)


mins.pack(side=LEFT)

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])

secs = OptionMenu(frame, second, *seconds)


secs.pack(side=LEFT)

Button(root,text="SetAlarm",font=("Helvetica
15"),command=Threading).pack(pady=20)
# Execute Tkinter
root.mainloop()

D. Y. Patil Technical Campus Faculty Of Engineering & Faculty Of Management,


Talsande (Polytechnic)
Create Simple Alarm Clock Using Class And Object

Output

D. Y. Patil Technical Campus Faculty Of Engineering & Faculty Of Management,


Talsande (Polytechnic)
Create Simple Alarm Clock Using Class And Object

D. Y. Patil Technical Campus Faculty Of Engineering & Faculty Of Management,


Talsande (Polytechnic)
Create Simple Alarm Clock Using Class And Object

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.

D. Y. Patil Technical Campus Faculty Of Engineering & Faculty Of Management,


Talsande (Polytechnic)
Create Simple Alarm Clock Using Class And Object

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/

D. Y. Patil Technical Campus Faculty Of Engineering & Faculty Of Management,


Talsande (Polytechnic)

You might also like