KEMBAR78
NOTEPAD MAKING IN PAYTHON BY ROHIT MALAV | PPSX
SUBMITTED BY:- ROHIT MALAV SUBMITTED TO:- MR.GAJANAND SIR
MAKING NOTEDPAD IN PAYTHON
OBJECTIVE:-
The thoughtfully designed software, making notepad using frame
system is meant for computer working in organisations. The
software is integrated with the data in the computer
organisation.
KEY HIGHLIGHTS
The barebone text editor
So here’s the starting code for a text editor:
import Tkinter import ScrolledText # Because Tkinter
textarea does not provide scrolling # abilities, we use
this additional library root = Tkinter.Tk(className="
Just another Text Editor") textPad =
ScrolledText.ScrolledText(root, width=100, height=80)
textPad.pack() root.mainloop()
Adding Menu Items
import Tkinter from Tkinter import Menu import ScrolledText root =
Tkinter.Tk(className="Just another Text Editor") textPad =
ScrolledText.ScrolledText(root, width=100, height=80) # creates
text area # create a menu def dummy(): print "I am a Dummy
Command, I will be removed in the next step" menu = Menu(root)
root.config(menu=menu) filemenu = Menu(menu)
menu.add_cascade(label="File", menu=filemenu)
filemenu.add_command(label="New", command=dummy)
filemenu.add_command(label="Open...", command=dummy)
filemenu.add_command(label="Save", command=dummy)
filemenu.add_separator() filemenu.add_command(label="Exit",
command=dummy) helpmenu = Menu(menu)
menu.add_cascade(label="Help", menu=helpmenu)
helpmenu.add_command(label="About...", command=dummy) #
end of menu creation textPad.pack() root.mainloop()
ADDING FUNCTIONALITY TO EACH MENU ITEM
import Tkinter from Tkinter import * from ScrolledText import *
import tkFileDialog import tkMessageBox root =
Tkinter.Tk(className=" Just another Text Editor") textPad =
ScrolledText(root, width=100, height=80) # create a menu &
define functions for each menu item def open_command():
file =
tkFileDialog.askopenfile(parent=root,mode='rb',title='Select
a file') if file != None: contents = file.read()
textPad.insert('1.0',contents) file.close() def
save_command(self): file =
tkFileDialog.asksaveasfile(mode='w') if file != None: # slice off
the last character from get, as an extra return is added
contents = file.read()
textPad.insert('1.0',contents) file.close() def
save_command(self): file =
tkFileDialog.asksaveasfile(mode='w') if file !=
None: # slice off the last character from get,
as an extra return is added data =
self.textPad.get('1.0', END+'-1c')
file.write(data) file.close() def
exit_command(): if
tkMessageBox.askokcancel("Quit", "Do you
really want to quit?"): root.destroy() def
about_command(): label =
tkMessageBox.showinfo("About", "Just
Another TextPad n Copyright n No rights
left to reserve")
def dummy(): print "I am a Dummy Command, I will be removed in the
next step" menu = Menu(root) root.config(menu=menu) filemenu =
Menu(menu) menu.add_cascade(label="File", menu=filemenu)
filemenu.add_command(label="New", command=dummy)
filemenu.add_command(label="Open...",
command=open_command) filemenu.add_command(label="Save",
command=save_command) filemenu.add_separator()
filemenu.add_command(label="Exit", command=exit_command)
helpmenu = Menu(menu) menu.add_cascade(label="Help",
menu=helpmenu) helpmenu.add_command(label="About...",
command=about_command) # textPad.pack() root.mainloop()
That gives us a simple Text Editor designed in Python & Tkinter with the
basic functionalities.
If you play with this code and add more functionalities, do let me know
in the comment section.
NOTEPAD  MAKING IN PAYTHON BY ROHIT MALAV

NOTEPAD MAKING IN PAYTHON BY ROHIT MALAV

  • 1.
    SUBMITTED BY:- ROHITMALAV SUBMITTED TO:- MR.GAJANAND SIR MAKING NOTEDPAD IN PAYTHON
  • 2.
    OBJECTIVE:- The thoughtfully designedsoftware, making notepad using frame system is meant for computer working in organisations. The software is integrated with the data in the computer organisation.
  • 3.
    KEY HIGHLIGHTS The barebonetext editor So here’s the starting code for a text editor: import Tkinter import ScrolledText # Because Tkinter textarea does not provide scrolling # abilities, we use this additional library root = Tkinter.Tk(className=" Just another Text Editor") textPad = ScrolledText.ScrolledText(root, width=100, height=80) textPad.pack() root.mainloop()
  • 4.
    Adding Menu Items importTkinter from Tkinter import Menu import ScrolledText root = Tkinter.Tk(className="Just another Text Editor") textPad = ScrolledText.ScrolledText(root, width=100, height=80) # creates text area # create a menu def dummy(): print "I am a Dummy Command, I will be removed in the next step" menu = Menu(root) root.config(menu=menu) filemenu = Menu(menu) menu.add_cascade(label="File", menu=filemenu) filemenu.add_command(label="New", command=dummy) filemenu.add_command(label="Open...", command=dummy) filemenu.add_command(label="Save", command=dummy) filemenu.add_separator() filemenu.add_command(label="Exit", command=dummy) helpmenu = Menu(menu) menu.add_cascade(label="Help", menu=helpmenu) helpmenu.add_command(label="About...", command=dummy) # end of menu creation textPad.pack() root.mainloop()
  • 5.
    ADDING FUNCTIONALITY TOEACH MENU ITEM import Tkinter from Tkinter import * from ScrolledText import * import tkFileDialog import tkMessageBox root = Tkinter.Tk(className=" Just another Text Editor") textPad = ScrolledText(root, width=100, height=80) # create a menu & define functions for each menu item def open_command(): file = tkFileDialog.askopenfile(parent=root,mode='rb',title='Select a file') if file != None: contents = file.read() textPad.insert('1.0',contents) file.close() def save_command(self): file = tkFileDialog.asksaveasfile(mode='w') if file != None: # slice off the last character from get, as an extra return is added
  • 6.
    contents = file.read() textPad.insert('1.0',contents)file.close() def save_command(self): file = tkFileDialog.asksaveasfile(mode='w') if file != None: # slice off the last character from get, as an extra return is added data = self.textPad.get('1.0', END+'-1c') file.write(data) file.close() def exit_command(): if tkMessageBox.askokcancel("Quit", "Do you really want to quit?"): root.destroy() def about_command(): label = tkMessageBox.showinfo("About", "Just Another TextPad n Copyright n No rights left to reserve")
  • 7.
    def dummy(): print"I am a Dummy Command, I will be removed in the next step" menu = Menu(root) root.config(menu=menu) filemenu = Menu(menu) menu.add_cascade(label="File", menu=filemenu) filemenu.add_command(label="New", command=dummy) filemenu.add_command(label="Open...", command=open_command) filemenu.add_command(label="Save", command=save_command) filemenu.add_separator() filemenu.add_command(label="Exit", command=exit_command) helpmenu = Menu(menu) menu.add_cascade(label="Help", menu=helpmenu) helpmenu.add_command(label="About...", command=about_command) # textPad.pack() root.mainloop() That gives us a simple Text Editor designed in Python & Tkinter with the basic functionalities. If you play with this code and add more functionalities, do let me know in the comment section.