scipiguy

FutureLearn GUIZero - Text Editor

Nov 11th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.42 KB | None | 0 0
  1. from guizero import App, TextBox, PushButton, Box, Combo, Slider
  2.  
  3. # Functions
  4. def open_file():
  5.     with open(file_name.value, "r") as f:
  6.         editor.value = f.read()
  7.  
  8. def save_file():
  9.     with open(file_name.value, "w") as f:
  10.         f.write(editor.value)
  11.  
  12. def change_font():
  13.     editor.font = font.value
  14.    
  15. def change_text_size():
  16.     editor.text_size = size.value
  17.     editor.resize(1, 1)
  18.     editor.resize("fill", "fill")
  19.    
  20. def change_font_colour():
  21.     editor.text_color = font_colour.value
  22.  
  23. app = App(title="Text Editor")
  24.  
  25. # Top box and widgets
  26. preferences_controls = Box(app, align="top", width="fill", border=True)
  27. font = Combo(preferences_controls, options=["courier", "stencil", "times new roman", "verdana"], align="left", command=change_font)
  28. size = Slider(preferences_controls, align="left", command=change_text_size, start=10, end=18)
  29. font_colour = Combo(preferences_controls, align="left", command=change_font_colour, options=["black", "blue", "green", "orange", "red", "yellow"])
  30.  
  31. editor = TextBox(app, multiline=True, height="fill", width="fill")
  32.  
  33. # Lower box and widgets
  34. file_controls = Box(app, align="top", width="fill")
  35. file_name = TextBox(file_controls, text="text_file.txt", width=50, align="left")
  36. save_button =PushButton(file_controls, text="Save", command=save_file, align="right")
  37. open_button = PushButton(file_controls, text = "Open", command=open_file, align="right")
  38.  
  39.  
  40. app.display()
Add Comment
Please, Sign In to add comment