hello world
lets make editor in python and enjoy
from tkinter import *
import os
import tkinter.filedialog

from tkinter import messagebox

from tkinter.colorchooser import askcolor

import datetime

import webbrowser

from tkinter.filedialog import askopenfilename, asksaveasfilename
filename=None
def line():
    lin = "_" * 60

    text.insert(INSERT,lin)

   

def date():

    data = datetime.date.today()

    text.insert(INSERT,data)

 

def normal():

    text.config(font = ("Arial", 10))



def bold():

    text.config(font = ("Arial", 10, "bold"))



def underline():

    text.config(font = ("Arial", 10, "underline"))



def italic():

    text.config(font = ("Arial",10,"italic"))

   

def font():

    (triple,color) = askcolor()

    if color:

       text.config(foreground=color)



def kill():
    t=messagebox.askyesnocancel('Alert','Do you want to exit')
    if t is True:
        root.destroy()
    else:
        pass

def rename():

    pass



def opn():

    text.delete(1.0 , END)

    file = open(askopenfilename() , 'r')

    if file != '':

        txt = file.read()

        text.insert(INSERT,txt)
    else:
        pass

    title()

def save():

    filename = asksaveasfilename(defaultextension='.txt'+'all file')

    if filename:

        alltext = text.get(1.0, END)                    

        open(filename, 'w').write(alltext)
    title()



def copy():

    text.clipboard_clear()

    text.clipboard_append(text.selection_get())



def paste():

    try:

        teext = text.selection_get(selection='CLIPBOARD')

        text.insert(INSERT, teext)

    except:

        tkMessageBox.showerror("Errore","Gli appunti sono vuoti!")



def cut():
   
        '''root.clipboard_clear()
        sel = text.get(SEL_FIRST, SEL_LAST)
        text.clipboard_append(sel=text.selection_get())'''

        text.delete(index1=SEL_FIRST,index2= SEL_LAST)



def clearall():

    text.delete(1.0 , END)



def background():

    (triple,color) = askcolor()

    if color:

       text.config(background=color)
def title():
    if filename!=None:
        title=os.path.basename(filename)
    else:
        title="untitled"
        root.title(title+'-'+TITLE)
     

def about():

    ab = Toplevel(root)

    txt = "sanjeev sukrail\ncontact:sanjeevsukrail@gmail.com"

    la = Label(ab,text=txt,foreground='blue')

    la.pack()

def undo():
    text.edit_undo()
def redo(event=None):
    text.edit_redo()

def web():
    webbrowser.open('http://www.enrixweb.altervista.org')
def new():
    global filename
    filename='untitled'
    text.delete(0.0,END)
def update():
    line=text.control.GetCurrent_line()+1
    col=text.control.GetColumn(control.GetCurrent_Pos())
    stat='Line %s,Column %s' %(line,col)
    StatusBar.setStatusText(stat)
root = Tk()
root.title("Sanjeev pad")
menu = Menu(root)
filemenu = Menu(root,tearoff=0)
root.config(menu = menu)
menu.add_cascade(label="File", menu=filemenu)
filemenu.add_command(label="New...",underline=2, command=new,accelerator='Ctrl+N')
filemenu.add_command(label="Open...", command=opn,accelerator='Ctrl+O')

filemenu.add_command(label="Save...", command=save,accelerator='Ctrl+s')

filemenu.add_separator()

filemenu.add_command(label="Kill", command=kill,accelerator='Alt+f4')
modmenu = Menu(root,tearoff=0)
menu.add_cascade(label="Modification",menu = modmenu)
modmenu.add_command(label="Copy", command = copy,accelerator='Ctrl+c')

modmenu.add_command(label="paste", command=paste,accelerator='Ctrl+v')

modmenu.add_separator()

modmenu.add_command(label = "Cut", command = cut,accelerator='Ctrl+x')

modmenu.add_command(label = "Clear all", command = clearall)

insmenu = Menu(root,tearoff=0)

menu.add_cascade(label="Insert",menu= insmenu)
insmenu.add_command(label="Data",command=date,accelerator='Ctrl+d')
insmenu.add_command(label="Undo",command=undo,accelerator='Ctrl+z')
insmenu.add_command(label="Redo",command=redo,accelerator='Ctrl+y')
insmenu.add_separator()
insmenu.add_command(label="Line",command=line,accelerator='Ctrl+l')  

formatmenu = Menu(menu,tearoff=0)

menu.add_cascade(label="Formate",menu = formatmenu)

formatmenu.add_cascade(label="font...", command = font)

formatmenu.add_separator()

formatmenu.add_radiobutton(label='Normal',command=normal)

formatmenu.add_radiobutton(label='Bold',command=bold,accelerator='Ctrl+b')

formatmenu.add_radiobutton(label='Underline',command=underline,accelerator='Ctrl+u')
formatmenu.add_radiobutton(label='Italic',command=italic,accelerator='Ctrl+i')
persomenu = Menu(root)
menu.add_cascade(label="Personalize",menu=persomenu)
persomenu.add_command(label="Background...", command=background)              
helpmenu = Menu(menu)
menu.add_cascade(label="Help", menu=helpmenu,accelerator='Ctrl+h'
helpmenu.add_command(label="About us", command=about)
helpmenu.add_command(label="Website", command = web)
text = Text(root, height=30, width=60, font = ("Verdana", 10),bd=8)
scroll = Scrollbar(root, command=text.yview)
scroll.config(command=text.yview)                
text.config(yscrollcommand=scroll.set)
scroll.pack(side=RIGHT, fill=Y)
statusbar=Label(root,bg='pink',text=update).pack(side=BOTTOM,fill=X)
text.pack()
root.resizable(0,0)
root.mainloop()

Comments