Advertisement
Vesna_To

text_editor

Aug 11th, 2019
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. from guizero import *
  2.  
  3. app = App(title="texteditor")
  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. def change_font():
  15. editor.font = font.value
  16.  
  17. def change_text_size():
  18. editor.text_size = size.value
  19. # resize the widget because if the text is made bigger, this might affect the size of the TextBox so guizero needs to know how to maintain the intended layout
  20. editor.resize(1, 1)
  21. editor.resize("fill", "fill")
  22.  
  23. def change_colour ():
  24. editor.text_color = font_c.value
  25.  
  26. # new Box for font, size and colour
  27.  
  28. preferences_controls = Box(app, width="fill", border=True)
  29.  
  30. font = Combo(preferences_controls, options=["Courier", "Times new roman", "Verdana", "Calibri", "Tahoma"], align="left", command=change_font)
  31. size = Slider(preferences_controls, align="left", command=change_text_size, start=10, end=18)
  32. font_c = Combo(preferences_controls, options=["Red", "Green", "Blue", "White", "Black", "Gray"], align="left", command=change_colour)
  33.  
  34. # box to house the controls, we want the box to span the entire width of the app
  35. file_controls = Box(app, align="bottom", width="fill")
  36.  
  37. # TextBox for the file name
  38. file_name = TextBox(file_controls, text="text_file.txt", width=50, align="left")
  39.  
  40. # save button which uses the save_file function
  41. save_button = PushButton(file_controls, text="Save", command=save_file, align="right")
  42.  
  43. # open button which uses the open_file function
  44. open_button = PushButton(file_controls, text="Open", command=open_file, align="right")
  45.  
  46.  
  47. # text
  48. editor = TextBox(app, multiline=True, height="fill", width="fill")
  49.  
  50. app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement