import os
import time
from tkinter import *
from tkinter.filedialog import *
from tkinter.messagebox import *
class Write( ) :
nametosave= ''
def savemy( ) :
txt = field.get ( 1.0 , END)
file = asksaveasfilename( )
Write.nametosave = file +'.txt'
if len ( file ) > 0 :
f= open ( file +'.txt' , 'w' )
f.write ( txt)
f.close ( )
def ctrl_s( e) :
if len ( Write.nametosave ) > 0 :
f= open ( Write.nametosave , 'w' )
txt = field.get ( 1.0 , END)
f.write ( txt)
f.close ( )
else :
Write.savemy ( )
def open_it( ) :
filetopen = askopenfilename( )
f= open ( filetopen, 'r' )
for elem in f:
field.insert ( 0.0 , elem)
f.close ( )
Write.nametosave = filetopen
def leave( ) :
if askyesno( 'Выход' , 'Сохранить файл?' ) :
savemy( )
else :
note.destroy ( )
def aboutme( ) :
showinfo( title= 'NoobPad' ,
message= '2015\n All rights reserved.©' )
def changestyle( nstyle) :
styles = [ [ 'black' , 'green' , 'System 16' ] , [ 'green' , 'red' , 'Impact 18' ] , [ 'white' , 'black' , 'Lucida 13' ] ]
field.configure ( bg= styles[ nstyle] [ 0 ] , fg= styles[ nstyle] [ 1 ] , font= styles[ nstyle] [ 2 ] )
def mycopy( e) :
note.clipboard_clear ( )
mytext = field.get ( SEL_FIRST, SEL_LAST)
note.clipboard_append ( mytext)
def mypaste( e) :
mytext= note.selection_get ( selection= 'CLIPBOARD' )
field.insert ( mytext)
def cut_it( e) :
note.clipboard_clear ( )
try :
mytext = field.get ( SEL_FIRST, SEL_LAST)
note.clipboard_append ( mytext)
text.delete ( SEL_FIRST, SEL_LAST)
except : pass
def underline( e) :
field.tag_config ( 'tag' , underline= 1 )
note.clipboard_clear ( )
t = field.get ( SEL_FIRST, SEL_LAST)
try :
field.delete ( SEL_FIRST, SEL_LAST)
field.insert ( INSERT, t, 'tag' )
except : pass
def bold( e) :
field.tag_config ( 'tag1' , font= 'Arial 8 bold' )
note.clipboard_clear ( )
t = field.get ( SEL_FIRST, SEL_LAST)
try :
field.delete ( SEL_FIRST, SEL_LAST)
field.insert ( INSERT, t, 'tag1' )
except : pass
def italic( e) :
field.tag_config ( 'tag2' , font= 'Arial 8 italic' )
note.clipboard_clear ( )
t = field.get ( SEL_FIRST, SEL_LAST)
try :
field.delete ( SEL_FIRST, SEL_LAST)
field.insert ( INSERT, t, 'tag2' )
except : pass
def normal( e) :
field.tag_config ( 'tn' , font= '' )
note.clipboard_clear ( )
t = field.get ( SEL_FIRST, SEL_LAST)
try :
field.delete ( SEL_FIRST, SEL_LAST)
field.insert ( INSERT, t, 'tn' )
except : pass
def select_all( e) :
field.tag_add ( SEL, 1.0 , END)
field.mark_set ( INSERT, 1.0 )
field.see ( INSERT)
return 'break'
def mytime( ) :
t = time .ctime ( )
field.insert ( END, t)
note = Tk( )
note.title ( 'NoobPad' )
mymenu = Menu( note)
note.config ( menu= mymenu)
firstmenu = Menu( mymenu)
mymenu.add_cascade ( label= 'Файл' , menu = firstmenu)
secondmenu = Menu( mymenu)
mymenu.add_cascade ( label= 'Настройки' , menu = secondmenu)
thirdmenu = Menu( mymenu)
fouthmenu= Menu( mymenu)
mymenu.add_cascade ( label= 'Формат' , menu = fouthmenu)
mymenu.add_cascade ( label= 'Справка' , menu = thirdmenu)
in3menu = Menu( thirdmenu)
firstmenu.add_command ( label= 'Сохранить' , command= Write.savemy )
firstmenu.add_command ( label= 'Открыть' , command= Write.open_it )
firstmenu.add_command ( label= 'Выйти' , command= Write.leave )
secondmenu.add_cascade ( label= 'Стиль' , menu= in3menu)
fouthmenu.add_command ( label= 'Выделить всё' , command= lambda event= '<Button-1>' : Write.select_all ( '<Button-1>' ) )
fouthmenu.add_command ( label= 'Время и дата' , command= Write.mytime )
in3menu.add_command ( label= 'Matrix' , command= lambda event= '<Button-1>' : Write.changestyle ( 0 ) )
in3menu.add_command ( label= 'Lebedev' , command= lambda event= '<Button-1>' : Write.changestyle ( 1 ) )
in3menu.add_command ( label= 'Normal' , command= lambda event= '<Button-1>' : Write.changestyle ( 2 ) )
thirdmenu.add_command ( label= 'О программе' , command= Write.aboutme )
field = Text( height= 50 , width= 200 , bg= 'white' , fg= 'black' )
field.bind ( '<Control-s>' , Write.ctrl_s )
field.bind ( '<Control-c>' , Write.mycopy )
field.bind ( lambda event= '<Control-v>' : Write.mypaste )
field.bind ( '<Control-x>' , Write.cut_it )
field.bind ( '<Control-b>' , Write.bold )
field.bind ( '<Control-i>' , Write.italic )
field.bind ( '<Control-u>' , Write.underline )
field.bind ( '<Control-n>' , Write.normal )
field.bind ( '<Control-a>' , Write.select_all )
field.pack ( )
note.mainloop ( )
aW1wb3J0IG9zCmltcG9ydCB0aW1lCmZyb20gdGtpbnRlciBpbXBvcnQgKgpmcm9tIHRraW50ZXIuZmlsZWRpYWxvZyBpbXBvcnQgKgpmcm9tIHRraW50ZXIubWVzc2FnZWJveCBpbXBvcnQgKgpjbGFzcyBXcml0ZSgpOgogICAgbmFtZXRvc2F2ZT0nJwogICAgZGVmIHNhdmVteSgpOgogICAgICAgIHR4dCA9IGZpZWxkLmdldCgxLjAsRU5EKQogICAgICAgIGZpbGUgPSBhc2tzYXZlYXNmaWxlbmFtZSgpCiAgICAgICAgV3JpdGUubmFtZXRvc2F2ZSA9IGZpbGUrJy50eHQnCiAgICAgICAgaWYgbGVuKGZpbGUpID4gMDoKICAgICAgICAgICAgZj1vcGVuKGZpbGUrJy50eHQnLCd3JykKICAgICAgICAgICAgZi53cml0ZSh0eHQpCiAgICAgICAgICAgIGYuY2xvc2UoKQoKICAgIGRlZiBjdHJsX3MoZSk6CiAgICAgICAgaWYgbGVuKFdyaXRlLm5hbWV0b3NhdmUpID4gMDoKICAgICAgICAgICAgZj1vcGVuKFdyaXRlLm5hbWV0b3NhdmUsJ3cnKQogICAgICAgICAgICB0eHQgPSBmaWVsZC5nZXQoMS4wLEVORCkKICAgICAgICAgICAgZi53cml0ZSh0eHQpCiAgICAgICAgICAgIGYuY2xvc2UoKQogICAgICAgIGVsc2U6CiAgICAgICAgICAgIFdyaXRlLnNhdmVteSgpICAgCgogICAgZG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aWMoZSk6CiAgICAgICAgZmllbGQudGFnX2NvbmZpZygndGFnMicsZm9udD0nQXJpYWwgOCBpdGFsaWMnKQogICAgICAgIG5vdGUuY2xpcGJvYXJkX2NsZWFyKCkKICAgICAgICB0ID0gZmllbGQuZ2V0KFNFTF9GSVJTVCxTRUxfTEFTVCkKICAgICAgICB0cnk6CiAgICAgICAgICAgIGZpZWxkLmRlbGV0ZShTRUxfRklSU1QsU0VMX0xBU1QpCiAgICAgICAgICAgIGZpZWxkLmluc2VydChJTlNFUlQsdCwndGFnMicpCiAgICAgICAgZXhjZXB0OiBwYXNzCgogICAgZGVmIG5vcm1hbChlKToKICAgICAgICBmaWVsZC50YWdfY29uZmlnKCd0bicsZm9udD0nJykKICAgICAgICBub3RlLmNsaXBib2FyZF9jbGVhcigpCiAgICAgICAgdCA9IGZpZWxkLmdldChTRUxfRklSU1QsU0VMX0xBU1QpCiAgICAgICAgdHJ5OgogICAgICAgICAgICBmaWVsZC5kZWxldGUoU0VMX0ZJUlNULFNFTF9MQVNUKQogICAgICAgICAgICBmaWVsZC5pbnNlcnQoSU5TRVJULHQsJ3RuJykKICAgICAgICBleGNlcHQ6IHBhc3MKCiAgICBkZWYgc2VsZWN0X2FsbChlKToKICAgICAgICBmaWVsZC50YWdfYWRkKFNFTCwgMS4wLCBFTkQpCiAgICAgICAgZmllbGQubWFya19zZXQoSU5TRVJULCAxLjApCiAgICAgICAgZmllbGQuc2VlKElOU0VSVCkKICAgICAgICByZXR1cm4gJ2JyZWFrJwoKICAgIGRlZiBteXRpbWUoKToKICAgICAgICB0ID0gdGltZS5jdGltZSgpCiAgICAgICAgZmllbGQuaW5zZXJ0KEVORCx0KQogICAgICAgIApub3RlID0gVGsoKQpub3RlLnRpdGxlKCdOb29iUGFkJykKCm15bWVudSA9IE1lbnUobm90ZSkKbm90ZS5jb25maWcobWVudT1teW1lbnUpCgpmaXJzdG1lbnUgPSBNZW51KG15bWVudSkKbXltZW51LmFkZF9jYXNjYWRlKGxhY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