[ create a new paste ] login | about

Link: http://codepad.org/ezxcpi7Y    [ raw code | fork ]

Python, pasted on Jul 26:
import tkinter
from tkinter import *
from tkinter import scrolledtext

class TextEditor:

    def __init__(self, title="Just another Text Editor", width=100, height=60):
        self.root = tkinter.Tk(className=title)
        self.textPad = scrolledtext.ScrolledText(self.root, width=width, height=height)

    def open_command(self):
        file = tkinter.filedialog.askopenfile(parent=self.root, mode='rb', title='Select File to open')
        if file != None:
            contents = file.read()
            self.textPad.insert('1.0',contents)
            file.close()

    def save_command(self):
        file = tkinter.filedialog.asksaveasfile()
        if file!= None:
            data = self.textPad.get('1.0')
            file.write(data)
            file.close()

    def exit_command(self):
        if tkinter.messagebox.askokcancel("Really Quit!","Are you sure, you'll leave us now?"):
            self.root.destroy()

    def about_command(self):
        label = tkinter.mesagebox.showinfo("About we", "Just another text editor for ye!")
    
    def dummy(self):
        print ("I am a Dummy Command, I will be removed in the next step")

    def mainloop(self):
        self.menu = Menu(self.root)
        self.root.config(menu=self.menu)
        self.filemenu = Menu(self.menu)
        self.menu.add_cascade(label="File", menu=self.filemenu)
        self.filemenu.add_command(label="New",command=self.dummy)
        self.filemenu.add_command(label="Open....", command=self.open_command)
        self.filemenu.add_command(label="Save", command=self.save_command)
        self.filemenu.add_separator()
        self.filemenu.add_command(label="Exit", command=self.exit_command)
        self.helpmenu = Menu(self.menu)
        self.menu.add_cascade(label="Help", menu=self.helpmenu)
        self.helpmenu.add_command(label="About...", command=self.about_command)
        self.textPad.pack()
        self.root.mainloop()

texteditor = TextEditor()
texteditor.mainloop()


Create a new paste based on this one


Comments: