You are on page 1of 45

INDUSTRIAL TRAINING REPORT

Music Player using Python

Submitted in partial fulfillment of the


Requirements for the award of

Degree of Bachelor of Technology in Computer Science & Engineering

Submitted By
Name: AKSHAY KUMAR SINGH
University Roll No: 1603310026

SUBMITTED TO:
Department of Computer Science & Engineering
RAJ KUMAR GOEL INSTITUTE OF TECHNOLOGY,GHAZIABAD

1
DECLARATION

I hereby declare that the Industrial Training Report entitled “MUSIC PLAYER USING
PYTHON ” by AKSHAY KUMAR SINGH (1603310026), is an authentic record of my own
work as requirements of Industrial Training during the period from 20 JUNE 2019 to
19 JULY 2019 for the award of degree of B.Tech (Computer Science & Engineering), RKGIT,
Ghaziabad .

AKSHAY KUMAR SINGH


Date: 24 NOVEMBER 2019 ​(1603310026)

2
VISION & MISSION

VISION OF THE INSTITUTE


To continually develop excellent professionals capable of providing sustainable solutions to
challenging problems in their fields and prove responsible global citizens.

MISSION OF THE INSTITUTE


We wish to serve the nation by becoming a reputed deemed university for providing value based
professional education.

VISION OF THE DEPARTMENT


To be recognized globally for delivering high quality education in the ever changing field of
computer science & engineering, both of value & relevance to the communities we
serve.
MISSION OF THE DEPARTMENT
1. To provide quality education in both the theoretical and applied foundations of Computer
Science and train students to effectively apply this education to solve real world problems.
2. To amplify their potential for lifelong high quality careers and give them a competitive
advantage in the challenging global work environment.

PROGRAM EDUCATIONAL OUTCOMES (PEOs)


PEO 1: Learning: Our graduates to be competent with sound knowledge in field of Computer
Science & Engineering.
PEO 2: Employable: ​To develop the ability among students to synthesize data and technical
concepts for application to software product design for successful careers that meet the needs of
Indian and multinational companies.
PEO 3: Innovative: ​To develop research oriented analytical ability among students to prepare
them for making technical contribution to the society.

3
PEO 4: Entrepreneur / Contribution: ​To develop excellent leadership quality among students
which they can use at different levels according to their experience and contribute for progress
and development in the society.

PROGRAM OUTCOMES (POs)


Engineering Graduates will be able to:
PO1: Engineering knowledge: Apply the knowledge of mathematics, science, engineering
fundamentals, and an engineering specialization to the solution of complex engineering
problems.
PO2: Problem analysis: Identify, formulate, review research literature, and analyze complex
engineering problems reaching substantiated conclusions using first principles of mathematics,
natural sciences, and engineering sciences.
PO3: Design/development of solutions: ​Design solutions for complex engineering problems
and design system components or processes that meet the specified needs with appropriate
consideration for the public health and safety, and the cultural, societal, and environmental
considerations.
PO4: Conduct investigations of complex problems:​ Use research-based knowledge research
methods including design of experiments, analysis and interpretation of data, and synthesis of the
information to provide valid conclusions.
PO5: Modern tool usage: ​Create, select, and apply appropriate techniques,resources, and
modern engineering and IT tools including prediction and modelling to complex engineering
activities with an understanding of the limitations.
PO6: The engineer and society: Apply reasoning informed by the contextual knowledge to
assess societal, health, safety, legal and cultural issues and the consequent responsibilities
relevant to the professional engineering practice.
PO7: Environment and sustainability: ​Understand the impact of the professional engineering
solutions in societal and environmental contexts, and demonstrate the knowledge of, and need
for sustainable development.

4
PO8: Ethics: Apply ethical principles and commit to professional ethics and responsibilities and
norms of the engineering practice.
PO9: Individual and team work: Function effectively as an individual, and as member or
leader in diverse teams, and in multidisciplinary settings.
PO10: Communication: Communicate effectively on complex engineering activities with the
engineering community and with society at large, such as, being able to comprehend and write
effective reports and design documentation, make effective

5
ACKNOWLEDGEMENT

It is our proud privilege and duty to acknowledge the kind of help and guidance received
from several people in preparation of this report. It would not have been possible to prepare
this report in this form without their valuable help, cooperation, and guidance.

First and foremost, we wish to record our sincere gratitude to Prof., ​Mr. Vishnu Khera ​for
his constant support and encouragement in the preparation of this report and for making
available library and laboratory facilities needed to prepare this report.

The seminar on ​“Python” ​was very helpful to us in giving the necessary background
information and inspiration in choosing this topic for the seminar. Their contributions and
technical support in preparing this report are greatly acknowledged.

Last but not least, we wish to thank our parents for financing our studies in this college as
well as for constantly encouraging us to learn to engineer. Their personal sacrifice in
providing this opportunity to learn engineering is gratefully acknowledged.

ANUBHAV KUMAR SINGH

6
ABOUT COMPANY

Tech Mentro was founded in 2009 with a mission to create skilled Software Engineers for our
country and the world. We are here to bridge the gap between the quality of skills demanded by
industry and the quality of skills imparted by conventional institutes. At Tech Mentro, we strive
to increase student interest by providing hands-on practical training on every concept taught in
the classroom.
We create confident developers who think beyond industrial jobs and march their ideas into
self-created entrepreneurship ventures. Skill and innovative thinking give developers the
confidence to transform their ideas into real-life products and hopefully go on to build
million-dollar companies.

7
CONTENTS
Title
Declaration
Vision & Mission
Abstract
About Company
Table of contents
List of figures
Certificate
Chapter
1. INTRODUCTION……………………………………………………….………...……..12
​ 1.1 Python Language Introduction ​……………………………….……….……..……..12
1.2 Script language​………………………………………………………..….…..……..12
1.3 Object-oriented programming (OOP)​.........................................................................13
1.4 History ​……………………………………………………..…...………..…..…...13
1.5 ​Behind The Scene of Python​………………………………………...………..…….15
2. DOWNLOAD AND INSTALLING………………………………………………...….16
​2.1 Download​……………………………………………………………………..……..16
2.2 Installing ​……………………………………………………………………...…....18
3. PYTHON FEATURES……………..………………………………………………........26
​3.1 Python Features​………………………………………………………………...……26
3.2 ​Python graphical user interfaces (GUIs)​......................................................................27
4.​ TKINTER​……………………………………………………………………….…...........28
​4.1 Tkinter​……………………………………………………………………….……..….28
4.2 Tkinter Widgets​………………………………………………………...…….…..…....29
4.3 Geometry Management​…………………………………………...………….…...…...32
4.4 Organizing Layout And Widgets​………………………………………..……….…..32
4.4.1 Grid​…………………………………………………………………….…….33

8
4.5 Binding Functions​ ​……………………………………………………….………..…..35
5. PYGAME​……………………………………………………………………..………..….36
6. IMPLEMENTATION​……………………………………………………....……...…......37
7. SNAPSHOTS​………………………………………………………………....…..….........39

8. ​USES AND Scope​………………………………………………………………………….40


​8.1 Scope of Python​………………………………………………………………………..40
8.2 What Can Do With Python?​………………………………..……………………….....40
​8.3 Uses Python Today​…………………………………………………..……………......40

8.4 ​Why Do People Use Python?​……………………………………………………..…..41


9. FEEDBACK FORM​………………………………………………………………...…....42
10. CONCLUSION​…………………………………………………………………...……..44
11. REFERENCE​……………………………………………………………………..……....45

9
LIST OF FIGURES

1. Fig-1.1………………………………………………………………………………………..14
2. Fig-2.1……………………………………………………………………………...………...16
3. Fig-2.2……………………………………………………………………………...………...17
4. Fig-2.3……………………………………………………………………………...………...17
5. Fig-2.4……………………………………………………………………………...………...18
6. Fig-2.5……………………………………………………………………………...………...19
7. Fig-2.6……………………………………………………………………………...………...20
8. Fig-2.7……………………………………………………………………………...………...21
9. Fig-2.8……………………………………………………………………………...………...21
10. Fig-2.9……………………………………………………………………………...……….22
11. Fig-2.10……………………………………………………………………………...……...23
12. Fig-2.11……………………………………………………………………………...………24
13. Fig-2.12……………………………………………………………………………...……....24
14. Fig-2.13……………………………………………………………………………...……....25
15. Fig-4.1……………………………………………………………………………...………..28
16. Fig-4.2……………………………………………………………………………...……….29
17. Fig-4.3……………………………………………………………………………...………..32
18. Fig-4.4……………………………………………………………………………...………..34
19. Fig-7.1……………………………………………………………………………...………..39

10
CERTIFICATE

11
CHAPTER-1
INTRODUCTION

1.1 PYTHON
Python is a widely-used general-purpose, high-level programming language. It was initially
designed by Guido van Rossum in 1991 and developed by Python Software Foundation. It was
mainly developed for emphasis on code readability, and its syntax allows programmers to
express concepts in fewer lines of code.
Python is a programming language that lets you work quickly and integrate systems more
efficiently. Python is a widely used high-level, general-purpose, interpreted, dynamic
programming language. Its design philosophy emphasizes code readability, and its syntax allows
programmers to express concepts in fewer lines of code than would be possible in languages
such as C++ or Java. The language provides constructs intended to enable clear programs on
both a small and large scale.

Python supports multiple programming paradigms, including object-oriented, Imperative and


functional programming or procedural styles. It features a dynamic type system and automatic
memory management and has a large and comprehensive standard library. Python interpreters
are available for installation on many operating systems, allowing Python code execution on a
wide variety of systems.

1.2 Scripting Language


A scripting or script language is a programming language that supports scripts, programs written
for a special run-time environment that automates the execution of tasks that could alternatively
be executed one-by-one by a human operator.
Scripting languages are often interpreted (rather than compiled). Primitives are usually the
elementary tasks or API calls, and the language allows them to be combined into more complex
programs. Environments that can be automated through scripting include software applications,

12
web pages within a web browser, the shells of operating systems (OS), embedded systems, as
well as numerous games.

A scripting language can be viewed as a domain-specific language for a particular environment;


in the case of scripting an application, this is also known as an ​extension language​. Scripting
languages are also sometimes referred to as very high-level programming languages, as they
operate at a high level of abstraction, or as control languages.

1.3 Object-Oriented Programming Language


Object-oriented programming (OOP) is a programming paradigm based on the concept of
"objects", which may contain data, in the form of fields, often known as attributes; and code, in
the form of procedures, often known as methods. A distinguishing feature of objects is that an
object's procedures can access and often modify the data fields of the object with which they are
associated (objects have a notion of "this" or "self").

In OO programming, computer programs are designed by making them out of objects that
interact with one another. There is significant diversity in object-oriented programming, but most
popular languages are class-based, meaning that objects are instances of classes, which typically
also determines their type.

1.4 ​History
Python was conceived in the late 1980s by ​Guido van Rossum​ at ​Centrum Wiskunde
Informatica​ (CWI) in the ​Netherlands​ as a successor to the ​ABC language​ (itself inspired
by ​SETL​), capable of ​exception handling​ and interfacing with the ​Amoeba​ operating
system.​[8]​ Its implementation began in December 1989. Van Rossum continued as Python's lead
developer until July 12, 2018, when he announced his "permanent vacation" from his
responsibilities as Python's ​Benevolent Dictator For Life​, a title the Python community bestowed
upon him to reflect his long-term commitment as the project's chief decision-maker.​[46]​ In
January 2019, active Python core developers elected Brett Cannon, Nick Coghlan, Barry
Warsaw, Carol Willing, and Van Rossum to a five-member "Steering Council" to lead the
project.

13
Python 2.0 was released on 16 October 2000 with many major new features, including
a ​cycle-detecting​ ​garbage collector​ and support for ​Unicode​.

Python 3.0 was released on 3 December 2008. It was a major revision of the language that is not
completely ​backward-compatible​.[39]​
​ Many of its major features were ​backported​ to Python 2.6.x
and 2.7.x version series. Releases of Python 3 include the ​2to3​ utility, which automates (at least
partially) the translation of Python 2 code to Python 3.​[41]

Python 2.7's ​end-of-life​ date was initially set in 2015 then postponed to 2020 out of concern that
a large body of existing code could not easily be forward-ported to Python 3.​[42] HYPERLINK

"https://en.wikipedia.org/wiki/Python_(programming_language)#cite_note-43"[43]​
In January 2017, Google announced work on a
Python 2.7 to ​Go​ ​transcompiler​ to improve performance under concurrent workloads

Fig- 1.1

14
“Python is an experiment in how much freedom programmers need. Too much
freedom and nobody can read another's code; too little and expressiveness is
endangered.”

- Guido van Rossum

1.5 Behind The Scene of Python


About the origin of Python, Van Rossum wrote in 1996
Over six years ago, on December 1989, I was looking for a "hobby" programming project that
would keep me occupied during the week around Christmas. My office ... would be closed, but I
had a home computer and not much else on my hands. I decided to write an interpreter for the
new scripting language I had been thinking about lately: a ​descendant of ABC ​that would appeal
to Unix/C hackers. I chose Python as a working title for the project, being in a slightly irreverent
mood (and a big fan of ​Monty Python's Flying Circus​).

15
​Chapter- 2

​DOWNLOADING AND INSTALLING

2.1 DOWNLOAD
If you don’t already have a copy of Python installed on your computer, you will need to open up
your Internet browser and go to the Python download page​ ​(h
​ ttp://www.python.org/download/).

fig-2.1

Now that you are on the download page, select which of the software builds you would like to
download. For the purposes of this article, we will use the most up to date version available
(Python 3.4.1).

16
fig-2.2

Once you have clicked on that, you will be taken to a page with a description of all the new
updates and features of 3.4.1, however, you can always read that while the download is in
process. Scroll to the bottom of the page till you find the “Download” section and click on the
link that says “download page.”

fig-2.3

Now you will scroll all the way to the bottom of the page and find the “Windows x86 MSI
installer.” If you want to download the 86-64 bit MSI, feel free to do so. We believe that even if
you have a 64-bit operating system installed on your computer, the 86-bit MSI is preferable. We

17
say this because it will still run well and sometimes, with the 64-bit architectures, some of the
compiled binaries and Python libraries don’t work well.

fig-2.4

2.2 Installing Python


Once you have downloaded the Python MSI, simply navigate to the download location on your
computer, double-clicking the file and pressing Run when the dialog box pops up.

18
​fig-2.5

If you are the only person who uses your computer, simply leave the “Install for all users” option
selected. If you have multiple accounts on your PC and don’t want to install it across all
accounts, select the “Install just for me” option then press “Next.”

19
fig-2.6

If you want to change the install location, feel free to do so; however, it is best to leave it as is
and simply select next, Otherwise...
Scroll down in the window and find the “Add Python.exe to Path” and click on the small red “x.”
Choose the “Will be installed on local hard drive” option then press “Next

20
fig-2.7

Now that you have completed the installation process, click on “Finish.

fig-2.8

21
Setup the Path Variable
Begin by opening the start menu and typing in “environment” and select the option called “Edit
the system environment variables.”

When the “System Properties” window appears, click on “Environment Variables…”

Once you have the “Environment Variables” window open, direct your focus to the bottom half.
You will notice that it controls all the “System Variables” rather than just this associated with
your user. Click on “New…” to create a new variable for Python.

fig-2.9

Simply enter a name for your Path and the code shown below. For the purposes of this example,
we have installed Python 2.7.3, so we will call the path: “Pythonpath.”

The string that you will need to enter is: “C:\Python27\;C:\Python27\Scripts;”

22
​fig-2.10

Running The Python IDE

Now that we have successfully completed the installation process and added our “Environment
Variable,” you are ready to create your first basic Python script. Let’s begin by opening Python’s
GUI by pressing “Start” and typing “Python” and selecting the “IDLE (Python GUI).

23
​fig-2.11

Once the GUI is open, we will begin by using the simplest directive possible. This is the “print”
directive which simply prints whatever you tell it to, into a new line. Start by typing a print
directive like the one shown in the image below or copy and paste this text then press

fig-2.12

“Enter”: print (“Congratulations on executing your first print directive!”)

24
Python Code Execution
Python’s traditional runtime execution model: source code you type is translated to byte code,
which is then run by the Python Virtual Machine. Your code is automatically compiled, but then
it is interpreted.

fig-2.13

Source code extension is .py

Byte code extension is .pyc (compiled python code)

25
​CHAPTER - 3

PYTHON FEATURES

3.1 Python Features:


• Easy-to-learn​ − Python has few keywords, simple structure, and a clearly defined
syntax. This allows the student to pick up the language quickly.
• Easy-to-read​ − Python code is more clearly defined and visible to the eyes.
• Easy-to-maintain​ − Python's source code is fairly easy-to-maintain.
• A broad standard library​ − Python's bulk of the library is very portable and
cross-platform compatible with UNIX, Windows, and Macintosh.
• Interactive Mode​ − Python has support for an interactive mode that allows interactive
testing and debugging of snippets of code.
• Portable​ − Python can run on a wide variety of hardware platforms and has the same
interface on all platforms.
• Extendable​ − You can add low-level modules to the Python interpreter. These modules
enable programmers to add to or customize their tools to be more efficient.
• Databases​ − Python provides interfaces to all major commercial databases.
• GUI Programming​ − Python supports GUI applications that can be created and ported
to many system calls, libraries and windows systems, such as Windows MFC, Macintosh, and
the X Window system of Unix.
• Scalable​ − Python provides a better structure and support for large programs than shell
scripting.
Apart from the above-mentioned features, Python has a big list of good features, few are listed
below −
• It supports functional and structured programming methods as well as OOP.
• It can be used as a scripting language or can be compiled to byte-code for building large
applications.
• It provides very high-level dynamic data types and supports dynamic type checking.

26
• IT supports automatic garbage collection.
• It can be easily integrated with C, C++, COM, ActiveX, CORBA, and Java.

3.2 Python graphical user interfaces (GUIs)


Python has a huge number of GUI frameworks (or toolkits) available for it,
from ​TkInter​ (traditionally bundled with Python, using Tk) to a number of other cross-platform
solutions, as well as bindings to platform-specific (also known as "native") technologies.

GUI​ is a desktop app that helps you to interact with computers. They are used to perform
different tasks in the desktops, laptops, other electronic devices, etc.., Here, we mainly talking
about the laptops and desktops.

• GUI​ apps like ​Text-Editors​ are used to create, read, update and delete different types of
files.

• GUI​ apps like ​Sudoku, Chess, Solitaire, etc..,​ are games that you can play.

• GUI​ apps like ​Chrome, Firefox, Microsoft Edge, etc..,​ are used to surf the ​Internet​.

They are some different types of ​GUI​ apps which we daily use on laptops or desktops.

27
​CHAPTER -4
​ ​TKINTER

4.1 Tkinter
Tkinter​ is an inbuilt ​Python​ module used to create simple ​GUI​ apps. It is the most commonly
used module for ​GUI​ apps in ​Python​.
You don't need to worry about the installation of the ​Tkinter​ module as it comes
with ​Python​ default

​fig-4.1

STEPS:-

• import the module ​Tkinter​.

• Initialize the window manager with the ​Tkinter.Tk()​ method and assign it to a
variable ​window​. This method creates a blank window with close, maximize and
minimize buttons.

• Rename the title of the window as you like with the ​window.title(title_of_the_window)​.

• The label​ is used to insert some objects into the ​window​. Here, we are adding
a ​label​ with some text.

• pack()​ attribute of the widget is used to display the ​widget​ in a size it requires.

• Finally, the ​mainloop()​ method to display the ​window​ until you manually close it.

28
That's a basic program to create a simple ​GUI​ interface​.

import Tkinter

window = tkinter.Tk()
# to rename the title of the window
window.title("GUI")
# pack is used to show the object in the window
label = tkinter.Label(window, text = "Hello World!").pack()

window.mainloop()

That's a basic program to create a simple ​GUI​ interface. You will see a similar window like this.

​fig-4.2

​4.2​ ​Tkinter Widgets


Widgets​ are something like elements in the ​HTML​. You will find different types of ​widgets​ to
the different types of elements in the ​Tkinter​.

Let's see a brief introduction to all of these widgets in the ​Tkinter​.

Operator & Description


Button
The Button widget is used to display buttons in your application.
Canvas

29
The Canvas widget is used to draw shapes, such as lines, ovals, polygons, and rectangles, in
your application.
Checkbutton
The Checkbutton widget is used to display a number of options as checkboxes. The user can
select multiple options at a time.
Entry
The Entry widget is used to display a single-line text field for accepting values from a user.
Frame
The Frame widget is used as a container widget to organize other widgets.
Label
The Label widget is used to provide a single-line caption for other widgets. It can also
contain images.
Listbox
The Listbox widget is used to provide a list of options to a user.
Menubutton
The Menu button widget is used to display menus in your application.
Menu
The Menu widget is used to provide various commands to a user. These commands are
contained inside Menubutton.
Message
The Message widget is used to display multiline text fields for accepting values from a user.
Radiobutton
The Radiobutton widget is used to display a number of options as radio buttons. The user can
select only one option at a time.
Scale
The Scale widget is used to provide a slider widget.
Scrollbar
The Scrollbar widget is used to add scrolling capability to various widgets, such as list
boxes.
Text
The Text widget is used to display text in multiple lines.
Toplevel
The Toplevel widget is used to provide a separate window container.
Spinbox
The Spinbox widget is a variant of the standard Tkinter Entry widget, which can be used to
select from a fixed number of values.
PanedWindow
A PanedWindow is a container widget that may contain any number of panes, arranged
horizontally or vertically
LabelFrame

30
A labelframe is a simple container widget. Its primary purpose is to act as a spacer or
container for complex window layouts.
tkMessageBox
This module is used to display message boxes in your applications.

4.3 Geometry Management

All widgets in the ​tkinter​ will have some geometry measurements. These measurements give
you to organize the widgets and their parent frames, windows, etc..,

Tkinter​ has the following three Geometry Manager classes.

• pack()​:- It organizes the widgets in the block, which mean it occupies the entire available
width. It's a standard method to show the widgets in the window

• grid()​:- It organizes the widgets in table-like structure. You will see details
about ​grid​ later in this tutorial.

• place()​:- It's used to place the widgets at a specific position you want.

4.4 Organizing Layout And Widgets


To arrange the layout in the ​window​, we will use ​Frame​, class. Let's create a simple
program to see how the ​Frame​ works.

Steps:-

• Frame​ is used to create the divisions in the window. You can align the frames as you like
with ​side​ parameter of ​pack()​ method.

• Button​ is used to create a button in the window. It takes several parameters


like ​text​(Value of the Button), ​fg​(Color of the text), ​bg​(Background color), etc..,

Note:-​ The parameter of any ​widget​ method must be where to place the widget. In the below
code, we use to place in the ​window​, ​top_frame​, ​bottom_frame​.

import tkinter

window = tkinter.Tk()

window.title("GUI")

The above code produces the following ​window​, if you didn't change the above code

31
# creating 2 frames TOP and BOTTOM

top_frame = tkinter.Frame(window).pack()

bottom_frame = tkinter.Frame(window).pack(side = "bottom")

# now, create some widgets in the top_frame and bottom_frame

btn1 = tkinter.Button(top_frame, text = "Button1", fg = "red").pack()# 'fg - foreground' is used


to color the contents

btn2 = tkinter.Button(top_frame, text = "Button2", fg = "green").pack()# 'text' is used to write


the text on the Button

btn3 = tkinter.Button(bottom_frame, text = "Button2", fg = "purple").pack(side = "left")# 'side'


is used to align the widgets

btn4 = tkinter.Button(bottom_frame, text = "Button2", fg = "orange").pack(side = "left")

window.mainloop()

#OUTPUT

​fig-4.3

4.4.1 Grid

Grid​ is another way to organize ​widgets​. It uses ​Matrix row-column​ concepts. Something like
this.

32
2 x 2 Matrix
00 01
10 11

EXAMPLE:-
import tkinter

window = tkinter.Tk()
window.title("GUI")

# creating 2 text labels and input labels

tkinter.Label(window, text = "Username").grid(row = 0) # this is placed in 0 0


# 'Entry' is used to display the input-field
tkinter.Entry(window).grid(row = 0, column = 1) # this is placed in 0 1

tkinter.Label(window, text = "Password").grid(row = 1) # this is placed in 1 0


tkinter.Entry(window).grid(row = 1, column = 1) # this is placed in 1 1

# 'Checkbutton' is used to create the check buttons


tkinter.Checkbutton(window, text = "Keep Me Logged In").grid(columnspan = 2) # 'columnspan'
tells to take the width of 2 columns
​# you can also use 'rowspan' in the similar manner

You will get the following output:

33
fig-4.4

4.5​ ​Binding Functions


Calling functions whenever an event occurs refers to a binding function.

• In the below example, when you click the button, it calls a function called ​say_hi​.

• Function ​say_hi​ creates a new label with the text ​Hi​.

EXAMPLE:-

window = tkinter.Tk()

window.title("GUI")

# creating a function called say_hi()

def say_hi():

tkinter.Label(window, text = "Hi").pack()

tkinter.Button(window, text = "Click Me!", command = say_hi).pack()

# 'command' is executed when you click the button

# in this above case we're calling the function 'say_hi'.

window.mainloop()

34
​CHAPTER-5
PYGAME

Pygame is a cross-platform set of Python modules designed for writing video games. It includes
computer graphics and sound libraries designed to be used with the Python programming
language.

Pygame was originally written by Pete Shinners to replace PySDL after its development stalled.
It has been a community project since 2000 and is released under the open source free software
GNU Lesser General Public License.

Pygame uses the Simple DirectMedia Layer (SDL) library, with the intention of allowing
real-time computer game development without the low-level mechanics of the C programming
language and its derivatives. This is based on the assumption that the most expensive functions
inside games can be abstracted from the game logic, making it possible to use a high-level
programming language, such as Python, to structure the game. Other features that SDL doesn't
have include vector math, collision detection, 2d sprite scene graph management, MIDI support,
camera, pixel-array manipulation, transformations, filtering, advanced freetype font support, and
drawing. Applications using pygame can run on Android phones and tablets with the use of
Pygame Subset for Android . Sound, vibration, keyboard, and accelerometer are supported on
Android.

35
​CHAPTER- 6
​ IMPLEMENTATION

IMPLEMENTATION
Technologies used​ - Python 3.6
Python Tkinter GUI
Pygame
Mutagen
Language used​ - Python

CODE OF PROJECT (MUSIC PLAYER )


import os
import pygame
from tkinter.filedialog import askdirectory
from tkinter import *
from mutagen.id3 import ID3
root=Tk()
root.minsize(300,300)
#songs array
listofsongs=[]
realnames=[]
index=0
v=StringVar()
songlabel=Label(root,textvariable=v,width=35)

def nextsong(event):
global index
index+=1
pygame.mixer.music.load(listofsongs[index])
pygame.mixer.music.play()
updatelabel()

def previoussong(event):
global index
index-=1
pygame.mixer.music.load(listofsongs[index])
pygame.mixer.music.play()
updatelabel()

def stopsong(event):

36
pygame.mixer.music.stop()
v.set("")
return songname

def updatelabel():
global index
global songname
v.set(realnames[index])
return songname

def directorychooser():
directory=askdirectory()
os.chdir(directory)

for files in os.listdir(directory):


if files.endswith(".mp3"):
realdir=os.path.realpath(files)
audio=ID3(realdir)
realnames.append(audio["TIT2"].text[0])
listofsongs.append(files)

pygame.mixer.init()
pygame.mixer.music.load(listofsongs[0])
pygame.mixer.music.play()

directorychooser()

label=Label(root,text="Music Player")
label.pack()

realnames.reverse()

listbox=Listbox(root)
listbox.pack()

listofsongs.reverse()

37
for items in realnames:
listbox.insert(0,items)

realnames.reverse()

nextbutton=Button(root,text="NEXT SONG")
nextbutton.pack()

previousbutton=Button(root,text="PREVIOUS SONG")
previousbutton.pack()

stopbutton=Button(root,text="STOP SONG")
stopbutton.pack()
#button-1 means left click
#button-2 means mid click
#button-3 means right click
nextbutton.bind("<Button-1>",nextsong)
previousbutton.bind("<Button-1>",previoussong)
stopbutton.bind("<Button-1>",stopsong)

songlabel.pack()

root.mainloop()

38
CHAPTER-7
SNAPSHOTS

Snapshots
GUI – Main display window with the name of the MUSIC PLAYER USING PYTHON

G​UI OF MUSIC PLAYER USING PYTHON

fig-7.1
It is a front end of the music player using python

1.Next Song:

after clicking this button play next song.

2.Previous Song

after clicking this button previous song.

3.Stop Song

after clicking this button stop song.​

39
​CHAPTER- 8
USES AND SCOPE

8.1 Scope of Python


Science
• Bioinformatics

System administration
• Unix

• Web logic

• Web sphere

Web Application Development

• GUI

• Testing scripts

8.2 What Can Do With Python?

• System programming
• Graphical User Interface

• Programming

• Component Integration

• Database Programming
• Gaming, Images, XML, Robot and more

8.3 Uses Python Today:


Python is being applied in real revenue-generating products by real companies.

40
• Google makes extensive use of Python in its web search system and
employs Python’s creator.
• Intel, Cisco, Hewlett-Packard, Seagate, Qualcomm, and IBM use Python for
hardware testing.
• ESRI uses Python as an end-user customization tool for its popular GIS
mapping products.
• The YouTube video sharing service is largely written in Python.

8.4 Why Do People Use Python?

The following primary factors cited by Python users seem

to be these:

• Python is object-oriented
• Structure supports such concepts as polymorphism, operation
overloading, and multiple inheritances.
• Indentation

• Indentation is one of the greatest future in Python.


• It's free (open source)
• Downloading and installing Python is free and easy
• Source code is easily accessible
• It's powerful
• Dynamic typing
• Built-in types and tools
• Library utilities
• Third-party utilities (e.g. Numeric, NumPy, SciPy)
• Automatic memory management
• It's portable
• Python runs virtually every major platform used today

41
42
43
​CONCLUSION

This project has really been faithful and informative. It has made us learn and understand the
many trivial concepts of Python Language. As we have used python Tkinter as a GUI it provides
various controls, such as buttons, labels and text boxes to build a user-friendly application.
The fast-growing use of the internet confirms the good future and scope of the proposed project.
Finally, it has taught us a valuable lifelong lesson about the improvements and working and
interacting in a group.

44
REFERENCES

[1]-​ ​https://www.w3schools.com/python/python_intro.asp
[2]- ​https://www.datacamp.com/community/tutorials/gui-tkinter-python#GUI
[3​]-​ ​https://www.geeksforgeeks.org/python-language-introduction/
[4​]-​ ​https://www.python.org
[5​]-​ ​https://www.wikipedia.org

45

You might also like