Advertisement
Guest User

Untitled

a guest
Feb 17th, 2020
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1.  
  2. # A new function that closes the app
  3. def exit_app():
  4. app.destroy()
  5.  
  6.  
  7.  
  8. def change_text_size():
  9. editor.text_size = size.value
  10. # 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
  11. editor.resize(1, 1)
  12. editor.resize("fill", "fill")
  13.  
  14. from guizero import App, TextBox, PushButton, Box, Combo, CheckBox, Slider, MenuBar, info
  15.  
  16. def open_file():
  17. with open(file_name.value, "r") as f:
  18. editor.value = f.read()
  19.  
  20. def save_file():
  21. with open(file_name.value, "w") as f:
  22. f.write(editor.value)
  23. save_button.hide()
  24. def change_font():
  25. editor.font = font.value
  26. def change_text_size():
  27. editor.text_size = size.value
  28. editor.resize(1, 1)
  29. editor.resize("fill", "fill")
  30.  
  31. def change_text_col():
  32. editor.text_color=(red.value,green.value,blue.value)
  33.  
  34. def enable_save():
  35. save_button.show()
  36.  
  37. def enable_open():
  38. open_button.show()
  39.  
  40. def about():
  41. info("about","this was made by JPA")
  42.  
  43. def helps():
  44. info("help:","if you need help - have a coffee")
  45.  
  46. app = App(title="textzero with menu")
  47.  
  48.  
  49.  
  50. menubar = MenuBar(app,
  51. toplevel=["File","Help"],
  52. options=[[["open",open_file],["save",save_file],["exit",exit_app]],
  53. [["about",about],["help",helps]]])
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61. file_controls = Box(app, align="top", width="fill", border=True)
  62. file_name = TextBox(file_controls, text="text_file.txt", width=50, align="left", command=enable_open)
  63. save_button = PushButton(file_controls, text="Save", command=save_file, align="right", visible=False)
  64. open_button = PushButton(file_controls, text="Open", command=open_file, align="right", visible=False)
  65.  
  66. editor = TextBox(app, multiline=True, height="fill", width="fill", command=enable_save)
  67.  
  68. preferences_controls = Box(app, align="bottom", width="fill", border=True)
  69. font = Combo(preferences_controls, options=["courier", "times new roman", "verdana"], align="left", command=change_font)
  70. size = Slider(preferences_controls, align="left", start = 8, end = 42, command=change_text_size)
  71. red = Slider(preferences_controls, align="left", start = 0, end = 255, command=change_text_col)
  72. green = Slider(preferences_controls, align="left", start = 0, end = 255, command=change_text_col)
  73. blue = Slider(preferences_controls, align="left", start = 0, end = 255, command=change_text_col)
  74. red.bg="red"
  75. green.bg="green"
  76. blue.bg="lightblue"
  77.  
  78.  
  79.  
  80.  
  81.  
  82. app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement