Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 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.  
  8. def save_file():
  9. with open(file_name.value, "w") as f:
  10. f.write(editor.value)
  11. app.info("info", "File Saved")
  12.  
  13. def change_font():
  14. editor.font = font.value
  15.  
  16. def change_text_size():
  17. editor.text_size = size.value
  18. editor.resize(1, 1)
  19. editor.resize("fill", "fill")
  20.  
  21. def change_text_color():
  22. editor.text_color = font_color.value
  23.  
  24. def change_background_color():
  25. editor.bg = background_color.value
  26.  
  27. app = App(title="GuiZeroTextEditor_v2" , width=900, height=800)
  28.  
  29. file_controls = Box(app, align="top", width="fill", border=True)
  30. file_name = TextBox(file_controls, text="text_file.txt", width=50, align="left")
  31. save_button = PushButton(file_controls, text="Save", command=save_file, align="right")
  32. open_button = PushButton(file_controls, text="Open", command=open_file, align="right")
  33.  
  34. editor = TextBox(app, multiline=True, height="fill", width="fill")
  35.  
  36. preferences_controls = Box(app, align="bottom", width="fill", border=True)
  37. font_name = Text(preferences_controls, text="Font:" , align ="left")
  38. font = Combo(preferences_controls, options=["Courier", "Times New Roman", "Verdana", "Piboto Condensed"], align="left", command=change_font)
  39. font_color_text = Text(preferences_controls, text="Font color:" , align ="left")
  40. font_color = Combo(preferences_controls, options=["black", "red", "green" , "blue" , "yellow"], align="left", command=change_text_color)
  41. background_color_text = Text(preferences_controls, text="Background color:" , align ="left")
  42. background_color = Combo(preferences_controls, options=["white", "black"], align="left", command=change_background_color)
  43. size = Slider(preferences_controls, align="left", start = 10, end = 42, command=change_text_size)
  44.  
  45. app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement