Advertisement
JAWarr

Text Editor V1

May 5th, 2022
1,305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.06 KB | None | 0 0
  1. # text editor V1 05/05/2022
  2. from guizero import App, TextBox, PushButton, Box
  3.  
  4. # function for reading files
  5. def open_file():
  6.     with open(file_name.value, "r") as f:
  7.         editor.value = f.read()
  8.  
  9. # function for writing files
  10. def save_file():
  11.     with open(file_name.value, "w") as f:
  12.         f.write(editor.value)
  13.  
  14. app = App(title="texteditor")
  15.  
  16. # create a box to house the controls, we want the box to span the entire width of the app
  17. file_controls = Box(app, align="top", width="fill")
  18.  
  19. # create a TextBox for the file name
  20. file_name = TextBox(file_controls, text="text_file.txt", width=50, align="left")
  21.  
  22. # create a save button which uses the save_file function
  23. save_button = PushButton(file_controls, text="Save", command=save_file, align="right")
  24.  
  25. # create an open button which uses the open_file function
  26. open_button = PushButton(file_controls, text="Open", command=open_file, align="right")
  27.  
  28. # create a TextBox which is not in the box and fills the rest of the GUI
  29. editor = TextBox(app, multiline=True, height="fill", width="fill")
  30.  
  31. app.display()
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement