Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. from guizero import App, Text, TextBox, PushButton, Box, Combo, CheckBox, Slider
  2.  
  3. def open_file():
  4. with open(file_name.value, "r") as f:
  5. editor.value = f.read()
  6. app.info("info", "File Opened")
  7. save_button.disable()
  8.  
  9. def save_file():
  10. with open(file_name.value, "w") as f:
  11. f.write(editor.value)
  12. app.info("info", "File Saved")
  13. save_button.disable()
  14. open_button.enable()
  15.  
  16. def enable_save():
  17. open_button.disable() # changes in text - "Open Button" disabled to not lose changes
  18. save_button.enable()
  19.  
  20. def change_font():
  21. editor.font = font.value
  22.  
  23. def change_text_size():
  24. editor.text_size = size.value
  25. editor.resize(1, 1)
  26. editor.resize("fill", "fill")
  27.  
  28. def change_text_color():
  29. editor.text_color = font_color.value
  30.  
  31. def change_background_color():
  32. editor.bg = background_color.value
  33.  
  34. app = App(title="GuiZeroTextEditor_v3" , width=900, height=800)
  35.  
  36. file_controls = Box(app, align="top", width="fill", border=True)
  37. file_name = TextBox(file_controls, text="text_file.txt", width=50, align="left")
  38. save_button = PushButton(file_controls, text="Save", command=save_file, align="right")
  39. open_button = PushButton(file_controls, text="Open", command=open_file, align="right")
  40.  
  41. editor = TextBox(app, multiline=True, height="fill", width="fill", command=enable_save)
  42.  
  43. preferences_controls = Box(app, align="bottom", width="fill", border=True)
  44. font_name = Text(preferences_controls, text="Font:" , align ="left")
  45. font = Combo(preferences_controls, options=["Courier", "Times New Roman", "Verdana", "Piboto Condensed"], align="left", command=change_font)
  46. font_color_text = Text(preferences_controls, text="Font color:" , align ="left")
  47. font_color = Combo(preferences_controls, options=["black", "red", "green" , "blue" , "yellow"], align="left", command=change_text_color)
  48. background_color_text = Text(preferences_controls, text="Background color:" , align ="left")
  49. background_color = Combo(preferences_controls, options=["white", "black"], align="left", command=change_background_color)
  50. size = Slider(preferences_controls, align="left", start = 10, end = 42, command=change_text_size)
  51.  
  52. save_button.disable() #nothing in editor - no save possibility
  53. app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement