Advertisement
Guest User

Untitled

a guest
Feb 17th, 2020
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. def change_text_size():
  2. editor.text_size = size.value
  3. # 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
  4. editor.resize(1, 1)
  5. editor.resize("fill", "fill")
  6.  
  7. from guizero import App, TextBox, PushButton, Box, Combo, CheckBox, Slider
  8.  
  9. def open_file():
  10. with open(file_name.value, "r") as f:
  11. editor.value = f.read()
  12.  
  13. def save_file():
  14. with open(file_name.value, "w") as f:
  15. f.write(editor.value)
  16.  
  17. def change_font():
  18. editor.font = font.value
  19.  
  20. def change_text_size():
  21. editor.text_size = size.value
  22. editor.resize(1, 1)
  23. editor.resize("fill", "fill")
  24.  
  25.  
  26. def change_text_col():
  27. editor.text_color=(red.value,green.value,blue.value)
  28.  
  29.  
  30. app = App(title="textzero")
  31.  
  32. file_controls = Box(app, align="top", width="fill", border=True)
  33. file_name = TextBox(file_controls, text="text_file.txt", width=50, align="left")
  34. save_button = PushButton(file_controls, text="Save", command=save_file, align="right")
  35. open_button = PushButton(file_controls, text="Open", command=open_file, align="right")
  36.  
  37. editor = TextBox(app, multiline=True, height="fill", width="fill")
  38.  
  39. preferences_controls = Box(app, align="bottom", width="fill", border=True)
  40. font = Combo(preferences_controls, options=["courier", "times new roman", "verdana"], align="left", command=change_font)
  41. size = Slider(preferences_controls, align="left", start = 8, end = 42, command=change_text_size)
  42. red = Slider(preferences_controls, align="left", start = 0, end = 255, command=change_text_col)
  43. green = Slider(preferences_controls, align="left", start = 0, end = 255, command=change_text_col)
  44. blue = Slider(preferences_controls, align="left", start = 0, end = 255, command=change_text_col)
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54. app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement