Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. from guizero import App, TextBox, PushButton, Box, Combo, CheckBox, Slider, MenuBar
  2.  
  3. def open_file():
  4. with open(file_name.value, "r") as f:
  5. editor.value = f.read()
  6.  
  7. def save_file():
  8. with open(file_name.value, "w") as f:
  9. f.write(editor.value)
  10. save_button.hide()
  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_text_color():
  21. editor.text_color = color.value
  22.  
  23. def enable_save():
  24. save_button.show()
  25.  
  26. def exit_app():
  27. app.destroy()
  28.  
  29. def change_bg_color(col):
  30. editor.bg = col
  31.  
  32. app = App(title="Text Editor 2")
  33.  
  34. menubar = MenuBar(app,
  35. toplevel=["File", "Background color"],
  36. options=[
  37. [["open",open_file], ["save",save_file], ["exit",exit_app]],
  38. [["red",lambda: change_bg_color('red')], ["blue",lambda: change_bg_color('blue')], ["cyan",lambda: change_bg_color('cyan')], ["magenta",lambda: change_bg_color('magenta')], ["light green",lambda: change_bg_color('light green')]]
  39. ])
  40.  
  41. file_controls = Box(app, align="top", width="fill")
  42. file_name = TextBox(file_controls, text="text_file.txt", width=50, align="left")
  43. save_button = PushButton(file_controls, text="Save", command=save_file, align="right")
  44. open_button = PushButton(file_controls, text="Open", command=open_file, align="right")
  45.  
  46. preferences_controls = Box(app, width="fill", border=True)
  47. font = Combo(preferences_controls, options=["courier", "times new roman", "verdana"], align="left", command=change_font)
  48. size = Slider(preferences_controls, align="left", start = 8, end = 42, command=change_text_size)
  49. color = Combo(preferences_controls, options=["black", "red", "cyan", "blue", "green", "magenta", "orange"], command=change_text_color)
  50. editor = TextBox(app, multiline=True, height="fill", width="fill", command=enable_save)
  51.  
  52. app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement