Advertisement
brendan-stanford

Texteditor-GUI

Oct 7th, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. from guizero import App, TextBox, PushButton, Box
  2.  
  3. app = App(title="texteditor")
  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 an open button which uses the open_file function
  19. open_button = PushButton(file_controls, text="Open", align="left", command = open_file)
  20.  
  21. # create a TextBox for the file name
  22. file_name = TextBox(file_controls, text="text_file.txt", width=50, align="left")
  23.  
  24. # create a save button which uses the save_file function
  25. save_button = PushButton(file_controls, text="Save", align="right", command = save_file)
  26.  
  27. # create a TextBox which is not in the box and fills the rest of the GUI
  28. editor = TextBox(app, multiline=True, height="fill", width="fill")
  29.  
  30. app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement