Advertisement
Buzzbow

basic text editor

Aug 19th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. from guizero import*
  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. #change font function
  16. def change_font():
  17. editor.font = font.value
  18.  
  19. def change_text_size():
  20. editor.text_size = size.value
  21. # 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
  22. editor.resize(1, 1)
  23. editor.resize("fill", "fill")
  24.  
  25. #change colour function
  26. def change_color(value):
  27. editor.text_color = value
  28.  
  29. # create a box to house the controls, we want the box to span the entire width of the app
  30. file_controls = Box(app, align="top", width="fill")
  31.  
  32. preferences_controls = Box(app, align="top", width="fill", border=True)
  33. font = Combo(preferences_controls, options=["courier", "times new roman", "verdana"], align="left", command=change_font)
  34.  
  35. # create a TextBox for the file name
  36. file_name = TextBox(file_controls, text="text_file.txt", width=50, align="left")
  37.  
  38. # create a save button which uses the save_file function
  39. save_button = PushButton(file_controls, text="Save", align="right", command = save_file)
  40.  
  41. # create an open button which uses the open_file function
  42. open_button = PushButton(file_controls, text="Open", align="right", command = open_file)
  43.  
  44. # create a TextBox which is not in the box and fills the rest of the GUI
  45. editor = TextBox(app, multiline=True, height="fill", width="fill")
  46.  
  47. #slider to control font size
  48. size = Slider(preferences_controls, align="left", command=change_text_size, start=10, end=18)
  49.  
  50. #change colour listbox
  51. lb_colour = ListBox(
  52. app,
  53. items=["red", "green", "blue", "yellow", "purple", "turquoise", "pink", "orange", "black", "brown", "cyan"],
  54. selected="black",
  55. command=change_color,
  56. scrollbar=True)
  57.  
  58.  
  59. app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement