crzcas

text editor

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