-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is a simple text editor using tkinter .
- Loading branch information
1 parent
d0cd84f
commit de09538
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import Tkinter | ||
from Tkinter import * | ||
from ScrolledText import * | ||
import tkFileDialog | ||
import tkMessageBox | ||
|
||
root = Tkinter.Tk(className=" My text editor -designed and developed by Shivang Shekhar") | ||
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(): | ||
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 life?"): | ||
root.destroy() | ||
|
||
def about_command(): | ||
label = tkMessageBox.showinfo("About", "I made it \n Copyright \n Fuck Yeah!") | ||
|
||
|
||
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() |