pisya

text editor

Nov 11th, 2019 (edited)
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.05 KB | None | 0 0
  1. from tkinter import *
  2. root = Tk()
  3.  
  4. def fopen():
  5.     try:
  6.         file_name = entry.get()
  7.         file = open(file_name)
  8.         text.delete(1.0, END)
  9.         text.insert(1.0, file.read())
  10.         file.close()
  11.     except:
  12.         pass
  13.  
  14. def fsave():
  15.     try:
  16.         file_name = entry.get()
  17.         file = open(file_name, 'w')
  18.         texting = text.get(1.0, END)
  19.         file.write(texting)
  20.         file.close()
  21.     except:
  22.         pass
  23.  
  24.  
  25. f1 = Frame()
  26. f2 = Frame()
  27. f3 = Frame()
  28. f1.pack()
  29. f2.pack(padx=3, pady=2)
  30. f3.pack()
  31.  
  32. entry = Entry(f1, width=50)
  33. entry.pack(side=LEFT)
  34. _open = Button(f1, width=10, text='open', command=fopen)
  35. _open.pack(side=LEFT, padx=3)
  36. save = Button(f1, width=10, text='save', command=fsave)
  37. save.pack(side=LEFT, padx=3)
  38. text = Text(f2, height=50, width=100)
  39. text.pack()
  40.  
  41. # -------scrollbar--------
  42. scrollY = Scrollbar(f2, command=text.yview)
  43. scrollY.pack(side=LEFT, fill=Y)
  44.  
  45. text.config(yscrollcommand=scrollY.set)
  46.  
  47. scrollX = Scrollbar(f3, command=text.xview)
  48. scrollX.pack(side=BOTTOM, fill=X)
  49.  
  50. text.config(xscrollcommand=scrollX.set)
  51.  
  52. root.title('Text editor')
  53. root.mainloop()
Add Comment
Please, Sign In to add comment