Itr Python
Itr Python
“PYTHON”
Submitted in partial fulfilment for the award of degree of
Bachelor of Technology
in
Department of Electronics & Communication Engineering
2022-2023
1 | Page
ACKNOWLEDGEMENT
There are always some key personalities whose roles are vital for the successful
completion of any work. However, it would not have been possible to complete this work
without the kind support and help of many individuals and organization. I would like to
extend my sincere thanks to all of them.
I am highly indebted to my mentors Mr. Lalit Kumar Lata, Assistant Professor & Mr.
Abhinandan Jain, Assistant Professor for their guidance and constant supervision as
well as for providing necessary information regarding the industrial training seminar &
also for their support in completing the Industrial Training. I would like to thank
Mr.Lalit Kumar Lata, Assistant Professor, Department of Electronics and
Communication, SKIT M & G, Jaipur for their kind support and guidance to complete
my Industrial Training Successfully. They helped us throughout the training. Their
excellent guidance has been instrumental in making this training a success.
I would like to thank Prof. (Dr.) Mukesh Arora, Professor & Head, Department of
Electronics and communication, SKIT M & G, Jaipur for providing me the opportunity to
do training in consistent direction and the adequate means and support to pursue this
training.
Finally, earnest and sincere thanks to all the Faculty members of Electronics and
Communication Department, SKIT M & G, Jaipur for their direct and indirect support in
the completion of this industrial training.
Last but not least, we sincerely express our deepest gratitude to our families for their
wholehearted support and encouragement to us to take up this course. In addition, a very
special thanks to our colleagues and friends for their support.
2 | Page
TABLE OF CONTENTS
Acknowledgement ii
Table of Content iii
Certificate iv
Chapter 1: Python
1.1 Introduction 5
1.2 Object oriented programming language 5
1.3 Scripting language 6
1.4 History of python 6
Chapter 2: Data Types
2.1 What is data types 7
2.2 Variables 7
2.3 Strings 8
2.4 Creating Strings 8
2.5 Python operators 8
3 | Page
Chapter 3: Tuples And Lists
3.1 Tuples 10
3.2 Accessing values in tuples 10
3.3 List 11
3.4 Accessing values in lists 11
Chapter 4: Loops
4.1 Loops 13
4.2 Conditional statements 14
4.3 Functions 15
Chapter 5: Project
5.1 Introduction 17
5.2 Code 18
5.3 Result 34
Chapter 6: Conclusion And References 35
4 | Page
CHAPTER 1: PYTHON
5 | Page
INTRODUCTION TO PYTHON :-
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.
SCRIPTING LANGUAGE:
6 | Page
A scripting or script language is a programming language that supports
scripts, programs written for a special run-time environment that automate
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, 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.
HISTORY OF PYTHON:
Python was conceived in the late 1980s, and its implementation was
started in December 1989 by Guido van Rossum at 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. Van Rossum is Python's principal author, and his continuing
central role in deciding the direction of Python is reflected in the title
given to him by the Python community, benevolent dictator for life
(BDFL).
7 | Page
WHAT IS DATA TYPES
VARIABLES
Variables are nothing but reserved memory locations to store values. This
means that when you create a variable you reserve some space in
memory.
Based on the data type of a variable, the interpreter allocates memory and
decides what can be stored in the reserved memory. Therefore, by
assigning different data types to variables, you can store integers,
decimals or characters in these variables.
Ex:
Counter = 100 # An integer assignment
miles = 1000.0 # A floating point
name = "John" # A string
STRINGS
8 | Page
In programming terms, we usually call text a string. When you think of a
string as a collection of letters, the term makes sense. All the letters,
numbers, and symbols in this book could be a string. For that matter, your
name could be a string, and so could your address.
CREATING STRINGS
PYTHON OPERATORS
9 | Page
ARITHMATIC OPERATORS:
10 | Page
CHAPTER 3: TUPLES AND LISTS
TUPLES:
For example −
tup1 = ('physics', 'chemistry', 1997, 2000);
tup2 = (1, 2, 3, 4, 5); tup3 = "a", "b", "c", "d";
To access values in tuple, use the square brackets for slicing along with
the index or
indices to obtain value available at that index. For example −
tup1 = ('physics', 'chemistry', 1997, 2000);
tup2 = (1, 2, 3, 4, 5, 6, 7 ); print "tup1[0]: ",
tup1[0]
print "tup2[1:5]: ", tup2[1:5]
When The above Code is executed, it produces the following result−
tup1[0]: physics
tup2[1:5]: [2, 3, 4, 5]
11 | Page
LIST
To access values in lists, use the square brackets for slicing along with the
index or indices to obtain value available at that index. For example −
Output:
list1[0]: physics
list2[1:5]: [2, 3, 4, 5]
12 | Page
Update: list = ['physics', 'chemistry', 1997, 2000];
print "Value available at index 2 : "
print list[2]
list[2] = 2001;
print "New value available at index 2 : "
print list[2]
Output:
Value available at index 2: 1997
New value available at index 2: 2001
13 | Page
CHAPTER 4: LOOPS
Example:
For Loop:
>>> for mynum in [1, 2, 3, 4, 5]:
print "Hello", mynum
Hello
1
Hello
2
Hello
3
Hello
4
Hello
5
14 | Page
While Loop:
>>> count = 0
>>> while (count < 4): print
'The count is:', count count =
count + 1
The count is: 0
The count is: 1
The count is: 2
The count is: 3
Conditional Statements:
STATEMENTS
Python programming language provides following types of decision making
statements.
Example:
If Statement:
>>> state = “Texas”
>>> if state == “Texas”:
print “TX
TX
15 | Page
If...Else Statement:
If...Else...If Statement:
FUNCTION
Function blocks begin with the keyword def followed by the function
name and parentheses ( ( ) ).
The code block within every function starts with a colon (:) and is
indented. The statement return [expression] exits a function, optionally
passing back an expression to the caller. A return statement with no
arguments is the same as return None.
16 | Page
Syntex:
Example:
# Now you can call printme function printme("I'm first call to user
defined function!") printme("Again second call to the same function")
17 | Page
CHAPTER 5: Project
Text Editor
Introduction:
Project details:
1 TKinter Module
2 Filedialouge
18 | Page
CODE
import tkinter as tk
from tkinter import Button, Image, StringVar, Tk, ttk
from tkinter import font,colorchooser,filedialog,messagebox
import os
main_application=tk.Tk()
main_application.geometry('1200x800')
main_application.title('text editor')
# edit icons
copy_icon=tk.PhotoImage(file='icons/copy.png')
paste_icon=tk.PhotoImage(file='icons/paste.png')
19 | Page
cut_icon=tk.PhotoImage(file='icons/cut.png')
clear_all_icon=tk.PhotoImage(file='icons/clear_all.png')
find_icon=tk.PhotoImage(file='icons/find.png')
# view icons
tool_bar_icon=tk.PhotoImage(file='icons/tool_bar.png')
status_bar_icon=tk.PhotoImage(file='icons/status_bar.png')
file=tk.Menu(main_menu,tearoff=False)
edit=tk.Menu(main_menu,tearoff=False)
view=tk.Menu(main_menu,tearoff=False)
colour_theme=tk.Menu(main_menu,tearoff=False)
theme_choice=tk.StringVar()
color_icons=(light_default_icon,light_plus_icon,red_icon,night_blue_icon,d
ark_icon,monokai_icon)
color_dict={
'Ligth Default' : ('#000000','#ffffff'),
20 | Page
'Ligth Plus' : ('#474747','#e0e0e0'),
'Dark' : ('#c4c4c4','#2d2d2d'),
'Red' : ('#2d2d2d','#ffe8e8'),
'Monokai' : ('#d3b774','#474747'),
'Night Blue' : ('#ededed','#6b9dc2')
}
# for view use cascade
main_menu.add_cascade(label='File',menu=file)
main_menu.add_cascade(label='Edit',menu=edit)
main_menu.add_cascade(label='View',menu=view)
main_menu.add_cascade(label='Colour Theme',menu=colour_theme)
21 | Page
# size box
size_family=tk.IntVar()
font_size=ttk.Combobox(tool_bar,width=14,textvariable=size_family,state='
readonly')
font_size['values']=tuple(range(6,100,2))
# align left btn
align_left_icon=tk.PhotoImage(file='icons/align_left.png')
align_left_btn=ttk.Button(tool_bar,image=align_left_icon)
align_left_btn.grid(row=0,column=6,padx=5)
# align center btn
align_center_icon=tk.PhotoImage(file='icons/align_center.png')
align_center_btn=ttk.Button(tool_bar,image=align_center_icon)
align_center_btn.grid(row=0,column=7,padx=5)
# align right btn
align_right_icon=tk.PhotoImage(file='icons/align_right.png')
align_right_btn=ttk.Button(tool_bar,image=align_right_icon)
align_right_btn.grid(row=0,column=8,padx=5)
#************************************************************
**************
########### TEXT EDITIOR ###################
text_editor=tk.Text(main_application)
text_editor.config(wrap='word',relief=tk.FLAT)
22 | Page
scroll_bar=tk.Scrollbar(main_application)
text_editor.focus_set()
scroll_bar.pack(side=tk.RIGHT,fill=tk.Y)
text_editor.pack(fill=tk.BOTH,expand=True)
scroll_bar.config(command=text_editor.yview)
text_editor.config(yscrollcommand=scroll_bar.set)
def fontsize_changer(main_application):
global current_font_size
23 | Page
current_font_size=size_family.get()
text_editor.configure(font=(current_font_family,current_font_size))
font_box.bind("<<ComboboxSelected>>",font_changer)
font_size.bind("<<ComboboxSelected>>",fontsize_changer)
text_editor.configure(font=(current_font_family,current_font_size,'bold'))
if text_property.actual()['weight']=='bold':
text_editor.configure(font=(current_font_family,current_font_size,'normal'))
bold_btn.configure(command=change_bold)
# for italic button
def change_italic():
text_property=tk.font.Font(font=text_editor['font'])
if text_property.actual()['slant']=='roman':
text_editor.configure(font=(current_font_family,current_font_size,'italic'))
24 | Page
if text_property.actual()['slant']=='italic':
text_editor.configure(font=(current_font_family,current_font_size,'roman'))
italic_btn.configure(command=change_italic)
# for underline button
def change_underline():
text_property=tk.font.Font(font=text_editor['font'])
if text_property.actual()['underline']==0:
text_editor.configure(font=(current_font_family,current_font_size,'underline
'))
if text_property.actual()['underline']==1:
text_editor.configure(font=(current_font_family,current_font_size,'normal'))
underline_btn.configure(command=change_underline)
#print(tk.font.Font(font=text_editor['font'].actual())
### for font color changer
def font_color():
color_var=tk.colorchooser.askcolor()
text_editor.configure(fg=color_var[1])
font_color_btn.configure(command=font_color)
text_editor.configure(font=('Arial',10))
# for align functanality
25 | Page
def align_right():
text_content=text_editor.get(1.0,'end')
text_editor.tag_config('right',justify=tk.RIGHT)
text_editor.delete(1.0,tk.END)
text_editor.insert(tk.INSERT,text_content,'right')
align_right_btn.configure(command=align_right)
### status bar funcationality
text_changed=False
def changed(event=None):
global text_changed
if text_editor.edit_modified():
text_changed=True
words=len(text_editor.get(1.0,'end-1c').split())
chara=len(text_editor.get(1.0,'end-1c'))
status_bar.config(text=f'Charcaters : {chara} Words : {words}')
text_editor.edit_modified(False)
text_editor.bind("<<Modified>>",changed)
#************************************************************
########### MAIN MENU FUNCATIONLITY ##########
url=''
26 | Page
# file commond
27 | Page
file.add_command(label='Open',image=open_icon,compound=tk.LEFT,acce
lerator='ctrl+O',command=open_file)
# save functionality
def save_file(event=None):
global url
try:
if url:
content=str(text_editor.get(1.0,tk.END))
with open(url,'w',encoding='utf-8') as fw:
fw.write(content)
else:
url = filedialog.asksaveasfile(mode = 'w', defaultextension='.txt',
filetypes=(('Text File', '.txt'), ('All files', '.*')))
content2=str(text_editor.get(1.0,tk.END))
url.write(content2)
url.close()
except:
return
file.add_command(label='Save',image=save_icon,compound=tk.LEFT,accel
erator='ctrl+S',command=save_file)
# save as functionality
def save_as_file(event=None):
global url
28 | Page
try:
content=text_editor.get(1.0, tk.END)
url = filedialog.asksaveasfile(mode = 'w', defaultextension='.txt',
filetypes=(('Text File', '.txt'), ('All files', '.*')))
url.write(content)
url.close()
except:
return
text_editor.config(font=('Arial',10))
file.add_command(label='Save_as',image=save_as_icon,compound=tk.LEF
T,accelerator='ctrl+Alt+S',command=save_as_file)
# exit functionality
def exit_file(event=None):
global url, text_changed
try:
if text_changed:
mbox = messagebox.askyesnocancel('Warning', 'Do you want to save
the file ?')
if mbox is True:
if url:
content = str(text_editor.get(1.0, tk.END))
29 | Page
with open(url, 'w', encoding='utf-8') as fw:
fw.write(content)
file.add_command(label='Save',image=save_icon,compound=tk.LEFT,accel
erator='ctrl+S',command=save_file)
# save as functionality
def save_as_file(event=None):
global url
try:
content=text_editor.get(1.0, tk.END)
url = filedialog.asksaveasfile(mode = 'w', defaultextension='.txt',
filetypes=(('Text File', '.txt'), ('All files', '.*')))
url.write(content)
url.close()
except:
return
text_editor.config(font=('Arial',10))
file.add_command(label='Save_as',image=save_as_icon,compound=tk.LEF
T,accelerator='ctrl+Alt+S',command=save_as_file)
# exit functionality
def exit_file(event=None):
global url, text_changed
30 | Page
try:
if text_changed:
mbox = messagebox.askyesnocancel('Warning', 'Do you want to save
the file ?')
if mbox is True:
if url:
content = str(text_editor.get(1.0, tk.END))
with open(url, 'w', encoding='utf-8') as fw:
fw.write(content)
file.add_command(label='Save',image=save_icon,compound=tk.LEFT,accel
erator='ctrl+S',command=save_file)
# save as functionality
def save_as_file(event=None):
global url
try:
content=text_editor.get(1.0, tk.END)
url = filedialog.asksaveasfile(mode = 'w', defaultextension='.txt',
filetypes=(('Text File', '.txt'), ('All files', '.*')))
url.write(content)
url.close()
except:
return
text_editor.config(font=('Arial',10))
file.add_command(label='Save_as',image=save_as_icon,compound=tk.LEF
T,accelerator='ctrl+Alt+S',command=save_as_file)
31 | Page
# exit functionality
def exit_file(event=None):
global url, text_changed
try:
if text_changed:
mbox = messagebox.askyesnocancel('Warning', 'Do you want to save
the file ?')
else:
content2 = str(text_editor.get(1.0, tk.END))
url = filedialog.asksaveasfile(mode = 'w', defaultextension='.txt',
filetypes=(('Text File', '.txt'), ('All files', '.*')))
url.write(content2)
url.close()
main_application.destroy()
elif mbox is False:
main_application.destroy()
else:
main_application.destroy()
except:
return
file.add_command(label='Exit',image=exit_icon,compound=tk.LEFT,acceler
ator='ctrl+Q',command=exit_file)
# edit commond
32 | Page
# copy
edit.add_command(label='Copy',image=copy_icon,compound=tk.LEFT,acc
elerator='ctrl+C',command=lambda: text_editor.event_generate("<Control
c>"))
text_editor.delete(1.0,tk.END)
edit.add_command(label='Clear
All',image=clear_all_icon,compound=tk.LEFT,accelerator='ctrl+Alt+z',com
mand=clear_all)
# find functionality
def find_func(event=None):
def find():
word=find_input.get()
text_editor.tag_remove('match','1.0',tk.END)
matches=0
if word:
start_pos='1.0'
while True:
start_pos=text_editor.search(word,start_pos,stopindex=tk.END)
if not start_pos:
break
end_pos=f'{start_pos}+{len(word)}c'
text_editor.tag_add('match',start_pos,end_pos)
matches+=1
start_pos=end_pos
33 | Page
text_editor.tag_config('match',foreground='black',background='red')
def Replace():
word=find_input.get()
replace_text=replace_input.get()
content=text_editor.get(1.0,tk.END)
new_content=content.replace(word,replace_text)
text_editor.delete(1.0,tk.END)
text_editor.insert(1.0,new_content)
find_dialog=tk.Toplevel()
find_dialog.geometry('450x250+500+200')
replace_input=ttk.Entry(findframe,width=30)
find_btn=ttk.Button(findframe,text='Find',command=find)
replace_btn=ttk.Button(findframe,text='Replace',command=Replace)
text_find_label.grid(row=0,column=0,padx=4,pady=4)
text_replace_label.grid(row=1,column=0,padx=4,pady=4)
find_dialog.mainloop()
edit.add_command(label='Find',image=find_icon,compound=tk.LEFT,accel
erator='ctrl+F',command=find_func)
# view commond
34 | Page
# VIEW FUNCTIONALITY
show_statusbar=tk.BooleanVar()
show_statusbar.set(True)
show_toolbar=tk.BooleanVar()
show_toolbar.set(True)
def hide_toolbar():
global show_toolbar
if show_toolbar:
tool_bar.pack_forget()
show_toolbar=False
else:
text_editor.pack_forget()
#status_bar.pack_forget()
tool_bar.pack(side=tk.TOP,fill=tk.X)
text_editor.pack(fill=tk.BOTH,expand=True)
#status_bar.pack(side=tk.BOTTOM)
show_toolbar=True
def hide_statusbar():
global show_statusbar
if show_statusbar:
status_bar.pack_forget()
35 | Page
show_statusbar=False
else:
text_editor.pack_forget()
status_bar.pack(side=tk.BOTTOM,fill=tk.Y)
text_editor.pack(fill=tk.BOTH,expand=True)
show_statusbar=True
view.add_checkbutton(label='Tool
Bar',onvalue=True,offvalue=False,variable =show_toolbar,
image=tool_bar_icon,compound=tk.LEFT,command=hide_toolbar)
view.add_checkbutton(label='Status
Bar',onvalue=True,offvalue=False,variable =show_statusbar,
image=status_bar_icon,compound=tk.LEFT,command=hide_statusbar)
# color theme commond
# colour theme functionality
def change_theme():
choose_theme=theme_choice.get()
colourtuple=color_dict.get(choose_theme)
fg_color,bg_color=colourtuple[0],colourtuple[1]
text_editor.config(background=bg_color,fg=fg_color)
count=0
for i in color_dict:
colour_theme.add_radiobutton(label=i,image=color_icons[count],variable=t
heme_choice,compound=tk.LEFT,command=change_theme)
count=count+1
#************************************************************
36 | Page
# bind shortcut key
main_application.config(menu=main_menu)
main_application.bind("<Control-n>",new_file)
main_application.mainloop()
Result :
Conclusion
37 | Page
So that’s how we have successfully made a text editor by python. This
text editor can write texts, can change fonts of the texts , can change the
alignment of the text, save it, copy, redo, undo etc. basically we have
made a little notepad with python in aur project.
References
● www.python.org
● www.studylib.net.in
● Techinnovation notes
● www.pythonforeverybody.in
38 | Page