fork download
  1. import os
  2. import time
  3. from tkinter import *
  4. from tkinter.filedialog import *
  5. from tkinter.messagebox import *
  6. class Write():
  7. nametosave=''
  8. def savemy():
  9. txt = field.get(1.0,END)
  10. file = asksaveasfilename()
  11. Write.nametosave = file+'.txt'
  12. if len(file) > 0:
  13. f=open(file+'.txt','w')
  14. f.write(txt)
  15. f.close()
  16.  
  17. def ctrl_s(e):
  18. if len(Write.nametosave) > 0:
  19. f=open(Write.nametosave,'w')
  20. txt = field.get(1.0,END)
  21. f.write(txt)
  22. f.close()
  23. else:
  24. Write.savemy()
  25.  
  26. def open_it():
  27. filetopen = askopenfilename()
  28. f=open(filetopen,'r')
  29. for elem in f:
  30. field.insert(0.0, elem)
  31. f.close()
  32. Write.nametosave = filetopen
  33.  
  34. def leave():
  35. if askyesno('Выход','Сохранить файл?'):
  36. savemy()
  37. else:
  38. note.destroy()
  39.  
  40. def aboutme():
  41. showinfo(title='NoobPad',
  42. message='2015\nAll rights reserved.©')
  43.  
  44. def changestyle(nstyle):
  45. styles = [['black','green','System 16'], ['green','red','Impact 18'], ['white','black','Lucida 13']]
  46. field.configure(bg=styles[nstyle][0],fg=styles[nstyle][1],font=styles[nstyle][2])
  47.  
  48. def mycopy(e):
  49. note.clipboard_clear()
  50. mytext = field.get(SEL_FIRST,SEL_LAST)
  51. note.clipboard_append(mytext)
  52.  
  53. def mypaste(e):
  54. mytext=note.selection_get(selection='CLIPBOARD')
  55. field.insert(mytext)
  56.  
  57. def cut_it(e):
  58. note.clipboard_clear()
  59. try:
  60. mytext = field.get(SEL_FIRST,SEL_LAST)
  61. note.clipboard_append(mytext)
  62. text.delete(SEL_FIRST,SEL_LAST)
  63. except: pass
  64.  
  65. def underline(e):
  66. field.tag_config('tag',underline=1)
  67. note.clipboard_clear()
  68. t = field.get(SEL_FIRST,SEL_LAST)
  69. try:
  70. field.delete(SEL_FIRST,SEL_LAST)
  71. field.insert(INSERT,t,'tag')
  72. except: pass
  73.  
  74. def bold(e):
  75. field.tag_config('tag1',font='Arial 8 bold')
  76. note.clipboard_clear()
  77. t = field.get(SEL_FIRST,SEL_LAST)
  78. try:
  79. field.delete(SEL_FIRST,SEL_LAST)
  80. field.insert(INSERT,t,'tag1')
  81. except: pass
  82.  
  83. def italic(e):
  84. field.tag_config('tag2',font='Arial 8 italic')
  85. note.clipboard_clear()
  86. t = field.get(SEL_FIRST,SEL_LAST)
  87. try:
  88. field.delete(SEL_FIRST,SEL_LAST)
  89. field.insert(INSERT,t,'tag2')
  90. except: pass
  91.  
  92. def normal(e):
  93. field.tag_config('tn',font='')
  94. note.clipboard_clear()
  95. t = field.get(SEL_FIRST,SEL_LAST)
  96. try:
  97. field.delete(SEL_FIRST,SEL_LAST)
  98. field.insert(INSERT,t,'tn')
  99. except: pass
  100.  
  101. def select_all(e):
  102. field.tag_add(SEL, 1.0, END)
  103. field.mark_set(INSERT, 1.0)
  104. field.see(INSERT)
  105. return 'break'
  106.  
  107. def mytime():
  108. t = time.ctime()
  109. field.insert(END,t)
  110.  
  111. note = Tk()
  112. note.title('NoobPad')
  113.  
  114. mymenu = Menu(note)
  115. note.config(menu=mymenu)
  116.  
  117. firstmenu = Menu(mymenu)
  118. mymenu.add_cascade(label='Файл',menu = firstmenu)
  119. secondmenu = Menu(mymenu)
  120. mymenu.add_cascade(label= 'Настройки',menu = secondmenu)
  121. thirdmenu = Menu(mymenu)
  122. fouthmenu=Menu(mymenu)
  123. mymenu.add_cascade(label='Формат', menu = fouthmenu)
  124. mymenu.add_cascade(label='Справка',menu = thirdmenu)
  125.  
  126. in3menu = Menu(thirdmenu)
  127. firstmenu.add_command(label='Сохранить',command=Write.savemy)
  128. firstmenu.add_command(label='Открыть', command=Write.open_it)
  129. firstmenu.add_command(label='Выйти', command=Write.leave)
  130. secondmenu.add_cascade(label='Стиль',menu=in3menu)
  131. fouthmenu.add_command(label='Выделить всё', command=lambda event='<Button-1>' : Write.select_all('<Button-1>'))
  132. fouthmenu.add_command(label='Время и дата',command= Write.mytime)
  133.  
  134. in3menu.add_command(label='Matrix', command=lambda event='<Button-1>' : Write.changestyle(0))
  135. in3menu.add_command(label='Lebedev', command=lambda event='<Button-1>' : Write.changestyle(1))
  136. in3menu.add_command(label='Normal', command=lambda event='<Button-1>' : Write.changestyle(2))
  137. thirdmenu.add_command(label='О программе', command=Write.aboutme)
  138. field = Text(height=50, width=200,bg='white',fg='black')
  139. field.bind('<Control-s>', Write.ctrl_s)
  140. field.bind('<Control-c>',Write.mycopy)
  141. field.bind(lambda event= '<Control-v>' : Write.mypaste)
  142. field.bind('<Control-x>',Write.cut_it)
  143. field.bind('<Control-b>',Write.bold)
  144. field.bind('<Control-i>',Write.italic)
  145. field.bind('<Control-u>',Write.underline)
  146. field.bind('<Control-n>',Write.normal)
  147. field.bind('<Control-a>',Write.select_all)
  148.  
  149. field.pack()
  150.  
  151. note.mainloop()
Runtime error #stdin #stdout #stderr 0.05s 26328KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "./prog.py", line 111, in <module>
  File "/usr/lib/python3.4/tkinter/__init__.py", line 1854, in __init__
    self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable