Advertisement
timber101

ColinsEditor

Aug 7th, 2019
204
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.17 KB | None
  1. from guizero import App, TextBox, PushButton, Box
  2.  
  3. app = App(title="Colin File Editor")
  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 saving files
  11. def save_file():
  12.     with open(file_name.value, "w") as f:
  13.         f.write(editor.value)
  14.  
  15. # create a TextBox which is not in the bottom box and fills the rest of the GUI
  16. editor = TextBox(app, multiline=True, height="fill", width="fill")
  17.  
  18. # create a box to house the controls, we want the box to span the entire width of the app
  19. file_controls = Box(app, align="bottom", width="fill")
  20.  
  21. #create some padding for the filename box
  22. pad = Box(file_controls, align="left", width=8, height= 1)
  23.  
  24. # create a TextBox for the file name
  25. file_name = TextBox(file_controls, text="text_file.txt", width=50, align="left")
  26.  
  27. # create a save button which uses the save_file function
  28. save_button = PushButton(file_controls, text="Save", command=save_file , align="right")
  29.  
  30. # create an open button which uses the open_file function
  31. open_button = PushButton(file_controls, text="Open", command=open_file, align="right")
  32.  
  33.  
  34. app.display()
Advertisement
RAW Paste Data Copied
Advertisement