Text Editor Using Python
Text Editor Using Python
PYTHON
PROJECT REPORT
BY
ANKIT KUMAR
18bca1104
INTRODUCTION
Python is developed by Guido van Rossum. Guido van Rossum started implementing Python
in 1989. Python is a very simple programming language so even if you are new to programming,
you can learn python without facing any issues
3. Cross platform: Python is available and can run on various operating systems such
as Mac, Windows, Linux, Unix etc. This makes it a cross platform and portable
language.
4. Open Source: Python is a open source programming language.
5. Large standard library: Python comes with a large standard library that has some
handy codes and functions which we can use while writing code in Python.
6. Free: Python is free to download and use. This means you can download it for free
and use it in your application. See: Open Source Python License. Python is an example
of a FLOSS (Free/Libre Open Source Software), which means you can freely distribute
copies of this software, read its source code and modify it.
7. Supports exception handling: If you are new, you may wonder what is an
exception? An exception is an event that can occur during program exception and can
disrupt the normal flow of program. Python supports exception handling which means
we can write less error prone code and can test various scenarios that can cause an
exception later on.
2. Machine learning – There are many machine learning applications written in Python.
Machine learning is a way to write a logic so that a machine can learn and solve a
particular problem on its own. For example, products recommendation in websites like
Amazon, Flipkart, eBay etc. is a machine learning algorithm that recognises user’s
interest. Face recognition and Voice recognition in your phone is another example of
machine learning.
3. Data Analysis – Data analysis and data visualisation in form of charts can also be
developed using Python.
4. Scripting – Scripting is writing small programs to automate simple tasks such as
sending automated response emails etc. Such type of applications can also be written
in Python programming language.
7. Desktop applications – You can develop desktop application in Python using library
like TKinter or QT.
INRO OF PROJECT:
PROS
Faster to Edit: For simple edits, it is often faster to make changes to a page
using a text editor.
Helps You Learn HTML: Text editors teach you to read HTML. They often
have wizards and functions to do the more common tasks (like the basic page
tags), but you'll learn HTML and basic coding if you use a text editor.
More Marketable: A web developer who can write HTML using a text editor
will be more marketable than one who can only use a WYSIWYG editor. The
former is more flexible and can get up to speed on any HTML editing tool,
while the latter has to start all over with each new editing tool.
No "Funky" HTML: The only HTML that will be in the document will be tags
that you placed there deliberately. This will help your pages download faster,
as well as look leaner.
Human Readable HTML: This is especially important if you work on a team
of web developers. The HTML can be spaced as your team likes it, and
include comments or other notes to allow more efficient editing by other team
members.
CONS
Must Know HTML: While most HTML text editors can help with tags and
suggest attributes and so on, these helpers are no substitute for knowing
HTML. Most modern text editors offer drag-and-drop styles such as bold and
italic, but if you can't remember the code for "non-breaking space" your editor
might not be able to help.
Steeper Learning Curve: Because you have to learn both HTML and the
editor functions itself, a beginner will find a text editor more difficult to use.
Harder to "Design" With: Some people find text editors more difficult to
design pages in because they can't visualize how the page will look from just
the HTML.
TECHNOLOGIES USED:
PYTHON
TKinter
GUI
SYSTEM RERQUIREMENTS:
HARDwARE
:-
The minimum hardware configuration for application to runis as
follows.
Microprocessor :- Intel Pentium600MHZ or equivalent
Ram: 256 mb
Hard drive 106.1 gb
Software:
Operating system
Windows:7/8/10
Algorithm:
The word Algorithm means “a process or set of rules to be followed in calculations or
other problem-solving operations”. Therefore Algorithm refers to a set of
rules/instructions that step-by-step define how a work is to be executed upon inorder
to get the expected results.
Flowchart:
import tkinter as tk
from tkinter import ttk
import os
main_application = tk.Tk()
main_application.geometry('1200x800')
main_application.wm_iconbitmap('icon.ico')
main_menu = tk.Menu()
#file icons
new_icon = tk.PhotoImage(file='icons2/new.png')
open_icon = tk.PhotoImage(file='icons2/open.png')
save_icon = tk.PhotoImage(file='icons2/save.png')
save_as_icon = tk.PhotoImage(file='icons2/save_as.png')
exit_icon = tk.PhotoImage(file='icons2/exit.png')
#####edit
#edit icons
copy_icon = tk.PhotoImage(file='icons2/copy.png')
paste_icon = tk.PhotoImage(file='icons2/paste.png')
cut_icon = tk.PhotoImage(file='icons2/cut.png')
clear_all_icon = tk.PhotoImage(file='icons2/clear_all.png')
find_icon = tk.PhotoImage(file='icons2/find.png')
tool_bar_icon = tk.PhotoImage(file='icons2/tool_bar.png')
status_bar_icon = tk.PhotoImage(file='icons2/status_bar.png')
light_default_icon = tk.PhotoImage(file='icons2/light_default.png')
light_plus_icon = tk.PhotoImage(file='icons2/light_plus.png')
dark_icon = tk.PhotoImage(file='icons2/dark.png')
red_icon = tk.PhotoImage(file='icons2/red.png')
monokai_icon = tk.PhotoImage(file='icons2/monokai.png')
night_blue_icon = tk.PhotoImage(file='icons2/night_blue.png')
theme_choice = tk.StringVar()
# 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)
############################################## toolbar
###################################################
tool_bar = ttk.Label(main_application)
tool_bar.pack(side=tk.TOP, fill=tk.X)
## font box
font_tuple = tk.font.families()
font_family = tk.StringVar()
font_box = ttk.Combobox(tool_bar, width=30, textvariable=font_family, state='readonly')
font_box['values'] = font_tuple
font_box.current(font_tuple.index('Arial'))
## size box
size_var = tk.IntVar()
font_size['values'] = tuple(range(8,81))
font_size.current(4)
## bold button
bold_icon = tk.PhotoImage(file='icons2/bold.png')
## italic button
italic_icon = tk.PhotoImage(file='icons2/italic.png')
## underline button
underline_icon = tk.PhotoImage(file='icons2/underline.png')
font_color_icon = tk.PhotoImage(file='icons2/font_color.png')
font_color_btn.grid(row=0, column=5,padx=5)
## align left
align_left_icon = tk.PhotoImage(file='icons2/align_left.png')
## align center
align_center_icon = tk.PhotoImage(file='icons2/align_center.png')
## align right
align_right_icon = tk.PhotoImage(file='icons2/align_right.png')
text_editor = tk.Text(main_application)
text_editor.config(wrap='word', relief=tk.FLAT)
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)
current_font_family = 'Arial'
current_font_size = 12
def change_font(event=None):
global current_font_family
current_font_family = font_family.get()
text_editor.configure(font=(current_font_family, current_font_size))
def change_fontsize(event=None):
global current_font_size
current_font_size = size_var.get()
text_editor.configure(font=(current_font_family, current_font_size))
font_box.bind("<<ComboboxSelected>>", change_font)
font_size.bind("<<ComboboxSelected>>", change_fontsize)
######## buttons functionality
def change_bold():
text_property = tk.font.Font(font=text_editor['font'])
if text_property.actual()['weight'] == 'normal':
if text_property.actual()['weight'] == 'bold':
bold_btn.configure(command=change_bold)
# italic functionlaity
def change_italic():
text_property = tk.font.Font(font=text_editor['font'])
if text_property.actual()['slant'] == 'roman':
if text_property.actual()['slant'] == 'italic':
italic_btn.configure(command=change_italic)
# underline functionality
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:
underline_btn.configure(command=change_underline)
def change_font_color():
color_var = tk.colorchooser.askcolor()
text_editor.configure(fg=color_var[1])
font_color_btn.configure(command=change_font_color)
def align_left():
text_editor.tag_config('left', justify=tk.LEFT)
text_editor.delete(1.0, tk.END)
align_left_btn.configure(command=align_left)
## center
def align_center():
text_content = text_editor.get(1.0, 'end')
text_editor.tag_config('center', justify=tk.CENTER)
text_editor.delete(1.0, tk.END)
align_center_btn.configure(command=align_center)
## right
def align_right():
text_editor.tag_config('right', justify=tk.RIGHT)
text_editor.delete(1.0, tk.END)
align_right_btn.configure(command=align_right)
text_editor.configure(font=('Arial', 12))
status_bar.pack(side=tk.BOTTOM)
text_changed = False
def changed(event=None):
global text_changed
if text_editor.edit_modified():
text_changed = True
text_editor.edit_modified(False)
text_editor.bind('<<Modified>>', changed)
## variable
url = ''
## new functionality
def new_file(event=None):
global url
url = ''
text_editor.delete(1.0, tk.END)
## file commands
## open functionality
def open_file(event=None):
global url
try:
text_editor.delete(1.0, tk.END)
text_editor.insert(1.0, fr.read())
except FileNotFoundError:
return
except:
return
main_application.title(os.path.basename(url))
## save file
def save_file(event=None):
global url
try:
if url:
fw.write(content)
else:
url.write(content2)
url.close()
except:
return
## save as functionality
def save_as(event=None):
global url
try:
url = filedialog.asksaveasfile(mode = 'w', defaultextension='.txt', filetypes=(('Text File', '*.txt'), ('All files', '*.*')))
url.write(content)
url.close()
except:
return
## exit functionality
def exit_func(event=None):
try:
if text_changed:
if mbox is True:
if url:
fw.write(content)
main_application.destroy()
else:
url.write(content2)
url.close()
main_application.destroy()
else:
main_application.destroy()
except:
return
def find_func(event=None):
def find():
word = find_input.get()
matches = 0
if word:
start_pos = '1.0'
while True:
if not start_pos:
break
end_pos = f'{start_pos}+{len(word)}c'
matches += 1
start_pos = end_pos
word = find_input.get()
replace_text = replace_input.get()
text_editor.delete(1.0, tk.END)
text_editor.insert(1.0, new_content)
find_dialogue = tk.Toplevel()
find_dialogue.geometry('450x250+500+200')
find_dialogue.title('Find')
find_dialogue.resizable(0,0)
## frame
find_frame.pack(pady=20)
## labels
## entry
## button
find_button = ttk.Button(find_frame, text='Find', command=find)
## label grid
## entry grid
## button grid
find_dialogue.mainloop()
## edit commands
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()
show_statusbar = False
else :
status_bar.pack(side=tk.BOTTOM)
show_statusbar = True
## color theme
def change_theme():
chosen_theme = theme_choice.get()
color_tuple = color_dict.get(chosen_theme)
text_editor.config(background=bg_color, fg=fg_color)
count = 0
for i in color_dict:
count += 1
main_application.config(menu=main_menu)
main_application.bind("<Control-o>", open_file)
main_application.bind("<Control-s>", save_file)
main_application.bind("<Control-Alt-s>", save_as)
main_application.bind("<Control-q>", exit_func)
main_application.bind("<Control-f>", find_func)
main_application.mainloop()
import cx_Freeze
import sys
import os
base = None
if sys.platform == 'win32':
base = "Win32GUI"
os.environ['TCL_LIBRARY'] = r"C:\Users\Admin\AppData\Local\Programs\Python\Python37\tcl\tcl8.6"
os.environ['TK_LIBRARY'] = r"C:\Users\Admin\AppData\Local\Programs\Python\Python37\tcl\tk8.6"
cx_Freeze.setup(
name = "Vpad Text Editor",
version = "0.01",
executables = executables
SCREENSHOTS: